Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is Hibernate creating a unique constraint when I don't want one?

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using Maven 1.1 to generate Oracle tables from my Java model, annotated using Hibernate 3.3.2.GA. My question is, what about my model is causing Hibernate to impose a unique constraint on the "payment_date" column? Here is how I have it set ...



and here is the resulting table generated using "maven generate-schema" ...



I don't want this unique constraint in there. Any ideas how to change my model so that it is not present when I generate a schema from the model? (complete model class is below). Thanks, - Dave


 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't used those annotations yet, but doesn't the annotation at line 22 put a unique constraint on payment_date?
 
Prabhat Jha
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup it does create.....

Here is the comment from hibernate annotation reference...

The @Table element also contains a schema and a catalog attributes, if they need to be defined. You can also define unique constraints to the table using the @UniqueConstraint annotation in conjunction with @Table (for a unique constraint bound to a single column, refer to @Column).

@Table(name="tbl_sky",
uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})}
)
A unique constraint is applied to the tuple month, day. Note that the columnNames array refers to the logical column names.


 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply but I don't think you fully read my post. I'm asking why did a unique constraint get created since I DID NOT specify "@UniqueConstraint", and the more important question is, what annotation can I include to prevent a unique constraint from being created on the "payment_date" column?

- Dave
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All apologies -- I actually did have a "uniqueConstraint" annotation at the very top of my class



and that is what was causing the undesired constraint upon table generation. Thanks for the help, - Dave
 
Prabhat Jha
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No worries
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic