-->
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.  [ 3 posts ] 
Author Message
 Post subject: unique property in HSQLDB?
PostPosted: Sat Dec 30, 2006 5:29 pm 
Newbie

Joined: Thu Jul 27, 2006 11:36 am
Posts: 10
Hibernate version: 3.1.3
HSQLDB version: 1.8.0.5

I am unable to get the unique="true" to do anything at all in HSQLDB. It seems like setting it to true or false has no effect at all one way or another.

Here is a snippet from my HBM file.
Code:
<!-- this is the display title for the user, must be unique -->
<property name="title" type="java.lang.String" unique="true">
    <column name="TITLE" not-null="true" length="255" />
</property>


I can insert 2 records into the DB using hibernate with the same title without an error of any kind.

Anyone have any ideas or thoughts or suggestions?
:-)
-AZ


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 31, 2006 1:35 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Well, it seems to do something in fact. Did you modify the schema or ask SchemaUpdate to do it? For me, it adds a unique(theColumn) at the end of the ddl of the table creation.

I just tested, if I try to use the same name on 2 instances, it throws a ConstraintViolationException.

Maybe you thought that Hibernate would perform a unique check if unique="true" is specified? If so, just be aware that this information is only used by the schema creation code, so as to generate the schema (and so the unique constraint). Hibernate can't simply do this check, because it would force it to load every instances of a class to do that check at each insert/update :-).

HTH

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 09, 2007 10:12 am 
Newbie

Joined: Tue Jan 09, 2007 10:06 am
Posts: 1
Location: Ireland
The following should do the trick, I believe:

Code:
<!-- this is the display title for the user, must be unique -->
<property name="title" type="java.lang.String" >
    <column name="TITLE" not-null="true" [b]unique="true" [/b]length="255" />
</property>


HTH,

Tara

_________________
Tara


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