-->
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: one column forming uniqueness with multiple different cols
PostPosted: Tue Jun 17, 2008 12:56 am 
Newbie

Joined: Tue Jun 17, 2008 12:35 am
Posts: 2
I have a requirement like where one column forms uniqueness with multiple different columns. For example consider columns A, B and C where A+B should be unique also A+C should be unique. I can't use unique-key or natural-id because they form uniqueness with whole combination i.e, A+B+C. At data base level I can specify A+B and A+C are unique. Could anybody please tell how to keep this constraint in hibernate mapping file.


Thanks,
Hari Prasad Alla


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 4:02 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
So, you're saying that using compound primary keys, even in combination, simply isn't a feasable option?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 10:23 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
I have not heard about multiple composite-id in one mapping...Wait for others reply...I'm in interested to hear more on this??

workaround: Give it a try..
You will be implementing the equals() and hashCode() to achieve the unqiueness...So write these checking in the above mehtods for your requirments..Hibernate will not error ....Only proper implementation of these methods will prevent duplication of composite PK's.

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 20, 2008 4:08 am 
Newbie

Joined: Tue Jun 17, 2008 12:35 am
Posts: 2
My mapping does not worry about defining PK or composite PK.

Code:
<hibernate-mapping>
<class entity-name="ITEM_ITEM_PC" table="ITEM_ITEM_PC">
   <id name="ID" type="long" column="ID" unsaved-value="0">
   <generator class="sequence">
   <param name="sequence">dyn_seq_28</param>
   </generator>
   </id>   
   <property name="USER_DOC_ID" type="string" column="USER_DOC_ID" not-null="true" unique-key="composite_unique" />
   <property name="IS_ACTIVE" type="boolean" column="IS_ACTIVE" not-null="true" />
   <property name="rtd_version" type="integer" column="rtd_version" not-null="true" unique-key="composite_unique" />
   <property name="TEMPLATE_NAME" column="TEMPLATE_NAME" type="string" />   
   <property name="ORDINAL" type="integer" column="ORDINAL" not-null="false" />   
   <property name="lineId" type="string" column="lineId" not-null="false" length="32" unique-key="composite_unique" />   
</class>
</hibernate-mapping>



In above mapping i have defined unique-key for "USER_DOC_ID", "rtd_version" and "lineId" which makes combination("USER_DOC_ID" + "rtd_version" + "lineId") unique. But i want uniqueness on ("USER_DOC_ID" + "rtd_version") and ("USER_DOC_ID" + "lineId").


my table script is,
Code:
CREATE TABLE  "ITEM_ITEM_PC"
   (   "ID" NUMBER(19,0) NOT NULL ENABLE,
   "TEMPLATE_NAME" VARCHAR2(255 CHAR) NOT NULL ENABLE,   
   "USER_DOC_ID" VARCHAR2(255 CHAR) NOT NULL ENABLE,
   "IS_ACTIVE" NUMBER(1,0) NOT NULL ENABLE,   
   "RTD_VERSION" NUMBER(10,0) NOT NULL ENABLE,   
   "ORDINAL" NUMBER(10,0),    
   "LINEID" VARCHAR2(32 CHAR),    
    PRIMARY KEY ("ID") ENABLE,
    UNIQUE ("USER_DOC_ID", "RTD_VERSION", "LINEID") ENABLE,
   )

And i can modify the constraint in script like UNIQUE ("USER_DOC_ID", "RTD_VERSION")
UNIQUE ("USER_DOC_ID", "LINEID")
to make ("USER_DOC_ID" + "rtd_version") and ("USER_DOC_ID" + "lineId") unique.
.

So i want to define same constraint at hbm level. I hope the problem is clear.

Thanks,
Hari Prasad Alla.


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.