-->
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: Unique key Index on multiple column in hibernate
PostPosted: Mon Jan 04, 2010 6:28 am 
Newbie

Joined: Mon Jan 04, 2010 6:23 am
Posts: 3
Hi,

I have a unique key constraint on a table named as suppose Employee, this key is made of using two columns(suppose Name& Join_date) in same table, can we create this unique key constraint using hbm/pojo in hibernate also for saving purpose. Currently I am just looking up object for unique key fields using criteria api and comparing in at java side and then saving if object not exist otherwise ignoring it, is there no way so that hibernate can directly check for unique key by making some changes in hbm or pojo.
If there is any other solution for it, Can anyone please suggest what changes need in hbm and pojo for this.


Thanks,
Sachin Panwar


Last edited by sachinpanwar on Tue Jan 05, 2010 9:24 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Unique key Index on multiple column in hibernate
PostPosted: Tue Jan 05, 2010 9:13 pm 
Newbie

Joined: Mon Jan 04, 2010 6:23 am
Posts: 3
sachinpanwar wrote:
Hi,

I have a unique key constraint on a table named as suppose Employee, this key is made of using two columns(suppose Name& Join_date) in same table, can we create this unique key constraint using hbm/pojo in hibernate also for saving purpose. Currently I am just looking up object for unique key fields using criteria api and comparing in at java side and then saving if object not exist otherwise ignoring it, is there no way so that hibernate can directly check for unique key by making some changes in hbm or pojo.
If there is any other solution for it, Can anyone please suggest what changes need in hbm and pojo for this.


Thanks,
Sachin Panwar



Here I am gettign unique key constraint error when trying to save other object with same unique Key, is there any way that we can set unique key with multiple columns in hbm/pojo file so that it can directly check for a unique key and ignore to save the object if key exist already..
I am trying it jut by lookup the object with unique key before saving it to DB and comparing if object with same values exits , I am ignoringing it otherwise saving it.

Thanks,
Sachin Panwar


Top
 Profile  
 
 Post subject: Re: Unique key Index on multiple column in hibernate
PostPosted: Sat Jan 23, 2010 8:00 am 
Newbie

Joined: Mon Jan 04, 2010 6:23 am
Posts: 3
Can Anyone help me out here..


Top
 Profile  
 
 Post subject: Re: Unique key Index on multiple column in hibernate
PostPosted: Wed Nov 17, 2010 7:12 am 
Beginner
Beginner

Joined: Tue Jun 30, 2009 7:05 am
Posts: 29
Location: Italy
Hi Sachin,
I know it's quite late to reply, and maybe you found a solution yet.
I'm facing the same problem: how to create unique indexes on multiple columns in mapping files.
I found the tag "properties" and applied my usual learn-by-doing approach. Actually it does what you think: create a [unique] index on the columns listed inside.
So, I went on with my project but there is a problem: Hibernate goes mad with aliases if they refer to the child properties of the tag "properties".
To explain, this is the mapping example I made (a simple localization labels storage):
Code:
   <class name="it.innove.multilanguage.entities.LabelText" table="innove_label_texts">
      <id name="id" column="id">
         <generator class="guid" />
      </id>
      <properties name="lnl" unique="true">
              <many-to-one name="language" column="language"
                 class="it.innove.multilanguage.entities.Language" fetch="select" lazy="false" />
              <many-to-one name="label" column="label"
                 class="it.innove.multilanguage.entities.Label" fetch="select" lazy="false" />
      <properties>
      <property name="text" type="string">
         <column name="text" sql-type="TEXT" />
      </property>
   </class>

but when I try to fetch LabelText objects I get an "Unknown column: alias_0x1_.language" error.

Is there anybody who has another solution?

Thanks,
Stefano


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.