|
Sponsored Links
Resources
Enterprise Java Research Library
Get Java white papers, product information, case studies and webcasts
|
EJB programming & troubleshooting
EJB programming & troubleshooting
EJB programming & troubleshooting
|
Messages: 4
Messages: 4
Messages: 4
Printer friendly
Printer friendly
Printer friendly
Post reply
Post reply
Post reply
XML
XML
XML
|
 |
another column as foreign key in Hibernate
Hi Experts
I have a table named "users" with columns : Id_user int username varchar password varchar
the id_user is primary key and incremental, but there is another table named "roles" I want to relation two table with column "username" but Hibernate use my primary key to join two table. how can I join two table with another column in a table, i dont want to join with primary key column.
my mapping in user.hbm.xml is: ..... <set name="roles" lazy="false" inverse="false" table="role"> <key column="userName" /> <one-to-many class="com.project.conf.value.Role" /> </set> ..... <there is a Set in class User>
hibernate use id_user to join table users with roles
pls help me....
|
|
Message #220603
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
It can't be done
It is my understanding that this can't be done.
Searching around the net shows that many people want to do the same thing but there is a notable silence from the Hibernate people in responding to this issue (even to tell people it can't be done).
|
|
Message #222981
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
use Property-ref to solve this problem
Hello I hope this ticket is not too late. Actually this issue can be solved easily. You can just put an attribe named property-ref in your key element. In your case, the hbm.xml file should be like following: <set name="roles" lazy="false" inverse="false" table="role"> <key column="userName" propery-ref="you specify name"/> <one-to-many class="com.project.conf.value.Role" /> </set> ..... And in many-to-one mapping, you should also specify the property-ref attribute. After you complete these steps. The hibernate will use the foreign key you specified instead of primary key.You can get more details in hibernate reference document.
Pingbo Ni
|
|
Message #233343
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
XDoclet tags
We use XDoclet (v1.2) to generate the mapping files. Our search for doing this with XDoclet tags didn't find anything. Seems like the property-ref tag in XDoclet is only available for "to-one" relationships, but not "to-many". Do you know how to do this?
|
|
Message #310640
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
property-ref does not always work
Discovered that property-ref can be a real pain when you have lazy loading, giving a message stating session is already closed. So better to use many-to-many instead, saves you a lot of hassle.
<set name="roles" lazy="false" inverse="false" table="role"> <key column="userName" propery-ref="you specify name"/> <many-to-many column="username" class="com.project.conf.value.Role"/> </set>
|
|
 |
Hot threads
Hot threads
Hot threads
|
More hot threads
More hot threads
More hot threads
|
 |
Brian Goetz continues to lift the lid and peak into the inner workings of Java in Java Urban Performance Legends. In this article he exposes the fallacy behind some of the more common performance myths found in the annals of the JVM.
(93 comments,
last posted
February 06, 2009)
Bruce Tate, author of Better, Faster Lighter Java and Bitter EJB has come out with a new book called Beyond Java. Bruce has an epiphany about the future of software development. Does it include Java?
(770 comments,
last posted
September 23, 2009)
Looks like today AJAX concept have several interpretations. We can distinguish different approaches of AJAX integration. Can they co-exist within the same application? Can we talk about layered AJAX integration?
(68 comments,
last posted
May 08, 2008)
Artima has published a short article describing the Design-Time API for JavaBeans, which was recently approved as JSR 273. This API promises to bring VB-like ease to Java development, but may face a cultural bias among Java developers who tend to think more in terms of class libraries than components.
(225 comments,
last posted
November 19, 2009)
There is plenty of speculation today regarding a potential buyout of Sun Microsystems by Scott McNealy and Silver Lake Partners. How would privatization of Sun affect Java?
(16 comments,
last posted
May 15, 2009)
More hot threads »
|
|