Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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


 
Marshal
Posts: 25814
69
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?
 
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
 
Your mother was a hamster and your father was a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic