-->
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.  [ 2 posts ] 
Author Message
 Post subject: Basic Question:Objects uniqueness and surrogate keys
PostPosted: Thu May 01, 2008 10:18 am 
Newbie

Joined: Wed Apr 30, 2008 1:49 pm
Posts: 7
Hi,

There is a basic problem which remains unclear to me.
I plan to create a set of persistent classes mapped with a surrogate key (of type guid) as their primary key. I also have some uniqueness constraint that I would like to comply with.
For instance, i have a Host class made unique by the "name" property. I don't want two Host objects with the same name to be persisted as two different objects. It then seems that there is a conflict between using a surrogate key and having uniqueness constraints. With a surrogate key as a primary key how can I enforce the uniqueness constraints ? Does this mean that using a surrogate key is not suited in this case ? (although surrogate keys are always recommended over natural keys) Am i bound to revert back to using a natural key ? (like using the name property as the primary key for the Host persistent class).

Thanks in advance,


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 01, 2008 10:26 am 
Beginner
Beginner

Joined: Wed Mar 05, 2008 4:57 am
Posts: 22
Location: Bangalore,India
Use "unique" constarint while mapping name property in the Host class.

<property name="name" unique="true" />.

So at all if you try to insert 2 objects with same name, you would be getting an exception.

_________________
Naresh Waswani
+91-9986461501


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