• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No worries
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic