-->
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: Composition of 2 tables in one domain object
PostPosted: Mon Feb 05, 2007 5:47 pm 
Newbie

Joined: Mon Feb 05, 2007 5:37 pm
Posts: 2
I use the following mapping doc for my domain object.

Mapping documents:

<hibernate-mapping package="dictionarytag">

<class name="DictionaryTag" table="resource">
...
<property name="firmId" column="firmId" type="java.lang.Long" not-null="true" length="20" unique="true"/>
...

<many-to-one name="firm"
class="firm"
column="firmId"
fetch="join"
update="false"
insert="false"
not-found="ignore"
not-null="false"
/>
</hibernate-mapping>


Now I would like to have a property in my DictionaryTag that maps to firm.name as if I had mapped it like this:
<property name="firmName" column="firm.name" type="string"/>

Any idea how I can achieve this?
Thx!

_________________
Reality emerge over time


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 11, 2007 4:43 pm 
Newbie

Joined: Mon Feb 05, 2007 5:37 pm
Posts: 2
I finally found how to do this using a join and a subselect as follow:

<join table="Firm" inverse="true" optional="true"
subselect="select res.id, firm.name from Resource res join Firm firm on res.FirmId=firm.id">
<key column="id"/>
<property name="firmName" column="name" insert="false" update="false"/>
</join>

_________________
Reality emerge over time


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.