-->
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.  [ 3 posts ] 
Author Message
 Post subject: how to derefrence a field
PostPosted: Thu May 05, 2005 11:59 pm 
Newbie

Joined: Thu May 05, 2005 11:54 pm
Posts: 3
Hi,

How can map following relationship model:

Person [pid, name, department_id]
Department[did, department_name]

to object model:

Person[pid, name, department_name]


Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 3:04 pm 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
There are several approaches. First, you can use a formula column:

Code:
<hibernate-mapping>
   <class name="Person" table="Person">
      <id name="pid" column="pid">
          <generator class="native"/>
      </id>
      <property name="name" column="name"/>
      <property name="department_name" formula="select name from department where did=department_id"/>
    </class>
</hibernate-mapping>


That should work, depending on your database. Not to question your model, but it might be worthwhile to have a Person POJO with a many-to-one mapping to a Department POJO, and, if necessary, create a view like this:

Code:
create view PersonView as
select p.pid, p.name, d.name
from person p inner join department d
on p.department_id=d.did


You could then create a POJO and mapping called PersonView and use that as needed.

- Jesse[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 3:10 pm 
Regular
Regular

Joined: Mon Feb 23, 2004 10:42 pm
Posts: 102
Location: Washington DC
Please follow directions and specify which version of hibernate you are using!!!!!!!!!!!

If you are using Hibernate3, then you might find this VERY useful :)
http://www.hibernate.org/hib_docs/v3/re ... ation-join

_________________
Matt Veitas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.