-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Adding A Unique Constraint
PostPosted: Tue Jan 06, 2004 5:16 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
I've got a SQL table in Oracle with a primary key that's generated by a sequence.

But that same table has a unique constraint on several columns in that same table that is NOT designated as a primary key. It could be considered an alternate key, but I wanted to use a surrogate key in my design.

It's easy enough to specify the surrogate key in Hibernate and XDoclet, but how do I also specify this unique constraint that's NOT a key? Is it possible?

The <composite-id> seems to be for tables with a composite key, and that's not strictly true in my case. - MOD

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 5:19 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
Did a search on the forum and found this:

http://forum.hibernate.org/viewtopic.ph ... constraint

Looks like unique constraints should be maintained by the database. That means hand editing the schema that I generate from XDoclet/Ant, but I think I'd have to do that anyway.

Sorry for not doing the search first. - MOD

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 5:40 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
Maybe I gave up too soon.

Is the Hibernate XDoclet @hibernate.column tag what I'm looking for? Is that the way to specify that columns A, B, and C together comprise a unique constraint in a table?

Where do they go in the Java source? The @hibernate.column tag is a method-level tag. Which getter does it go with - getA(), getB(), getC(), or all of them? - MOD

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 3:34 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
duffymo wrote:
http://forum.hibernate.org/viewtopic.php?t=926778&highlight=unique+constraint

Looks like unique constraints should be maintained by the database. That means hand editing the schema that I generate from XDoclet/Ant, but I think I'd have to do that anyway.

This topic is irrevelent in your case, Actually, that's what you wanted to do, let hbm2ddl generate the unique constraint in your DB.

I don't know hbm2ddl enough to know how to do what you want, there's still hope :)

I'm afraid @hibernate.column unique="true" on several columns will create several 1-column contraints, have a quick try however.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.