-->
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: unique-key
PostPosted: Mon Nov 19, 2007 11:02 pm 
Newbie

Joined: Mon Nov 19, 2007 10:54 pm
Posts: 2
Hi I am trying to generate a unique-key for a table.
I have read the docs and tried what it said but still am unable to achieve desired results
Eg
<class
name="test"
table="t_table_test">
<property
name="field_1"
column="FIELD_1"
access="field"
not-null="true"
unique-key="field_1_2"
/>

<property
name="field_2"
access="field"
not-null="true"
column="FIELD_2"
unique-key="field_1_2"
/>
</class>

But I am still able to insert the same data more than once.
Any help would be appreciated.

Thx


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 3:30 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi Shalvin,

Look into the thread below, Hope this helps:-)

http://forum.hibernate.org/viewtopic.ph ... highlight=

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 2:38 pm 
Newbie

Joined: Mon Nov 19, 2007 10:54 pm
Posts: 2
thx for the link
I am still not a 100% sure I know what to do. Do u have some sample that I could look at.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 21, 2007 8:49 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Gavin told us to use natural id for unique key....i have not tried it...Wait for others to reply..will try to do a sample and let you know...

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 26, 2007 2:51 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi Shalvin,

I did it this way to maintaing unique result in database.

Criteria criteria = session.createCriteria(User.class);
User user = (User) criteria.add(Restrictions.naturalId().set("userId", userId)).setCacheable(true).uniqueResult();

where User Id should be unique in this case.

Hope this helps:-)

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


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.