-->
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.  [ 1 post ] 
Author Message
 Post subject: Using join to map many-to-one
PostPosted: Thu Jul 28, 2011 8:35 pm 
Newbie

Joined: Thu Jul 28, 2011 8:17 pm
Posts: 3
Hi all,

We have a really restricted java data model and the class structure/code should not be changed. Here is the class (i simplified it)

Code:
class Person {
    private int id;
    private int roleId;
    private String roleName;
}



In the DB, There are two tables
Code:
person table ONLY has id and roleId

role table has roleId and roleName.



We will have to load both roleId and roleName into the Person object

And here are the mappings

Code:
<class name="Person" table="person">
   <id name="id"/>
   <property name="roleId"/>
   [b]<how to map roleName ???/>[/b]
</class>





I cannot seem to map the roleName, I have tried using join

Code:
<join table="role" optional="true">
   <key property-ref="roleId" column="roleId"/>
   <property name="roleName"/>
</join>


but the generated SQL code shows

LEFT OUTER JOIN ON person.id = role.roleId

instead of

LEFT OUTER JOIN ON person.roleId = role.roleId which I really want.

Property-ref seems to get ignored...Is there any way to get it working?

Zillion thanks in advance!!!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.