GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes Why is Hibernate creating a unique constraint when I don't want one? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Why is Hibernate creating a unique constraint when I don Watch "Why is Hibernate creating a unique constraint when I don New topic
Author

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

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Aug 13, 2007
Posts: 58
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.



Thanks,
Prabhat
SCJP 1.5, SCWCD 1.5, SCBCD 1.5
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
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

Joined: Jul 02, 2008
Posts: 436
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

Joined: Aug 13, 2007
Posts: 58
No worries
 
GeeCON Prague 2014
 
subject: Why is Hibernate creating a unique constraint when I don't want one?