-->
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.  [ 5 posts ] 
Author Message
 Post subject: [xDoclet] Constraint unique with more than one column
PostPosted: Mon Jan 03, 2005 11:14 am 
Newbie

Joined: Tue Nov 30, 2004 5:07 am
Posts: 14
Hi everybody,

I'm using Hibernate 2.2 with XDoclet to generate mapping files and sql-code for my Oracle 9 database. Now I want to define a unique key via XDoclet. To do so for a single property you have just to add:
Code:
@hibernate.property column="NAME" unique="true"

That works, no problems.

But how could I make two or more properties unique? For example I want the combination of "name" and "birthday" to appear only once in a table.
I tried with:
Code:
@hibernate.column unique-key="unique"

I thought that every column with the same unique-key would be included in a group of unique columns. But I get an Exception:
Code:
Schema text failed: java.lang.StringIndexOutOfBoundsException: String index out of range:0


Any suggestions what I did wrong? What should I change?

smo


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 03, 2005 6:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Looking at http://xdoclet.net/xdoclet/tags/hibernate-tags.html#@hibernate_column__0____
Shows that the column tag supports unique="true" so you should be able to set it that way if its a subset of the property. If you want separate properties to have a unique constraint across them, it will have to be defined in a separate DDL script.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 04, 2005 4:49 pm 
Newbie

Joined: Tue Nov 30, 2004 5:07 am
Posts: 14
Thanks for your answer. I think I will skip defining a seperate DDL script for now, but maybe will try this later..

smo


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 05, 2005 12:17 pm 
Newbie

Joined: Tue Nov 02, 2004 11:44 am
Posts: 8
Code:
unique-key = "MyConstraintName"
has worked for me. Try getting rid of unique keyword within double quotes.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 05, 2005 4:24 pm 
Newbie

Joined: Tue Nov 30, 2004 5:07 am
Posts: 14
Sorry, I don't know what I did wrong last time but it's working now, even with the "unique" keyword.

smo


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.