-->
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: Mapping multiple tables with composite key to single entity
PostPosted: Sat Aug 07, 2010 10:20 am 
Newbie

Joined: Sat Aug 07, 2010 9:53 am
Posts: 3
Hi I am new to the Hibernate and JPA. I have done some basic tutorials but I am stuck with this problem where
I need to create an entity which can take data from multiple tables and each table uses composite primary key.

In this example, companies can have multiple departments, each departments have multiple employees.
Based on the department employees manage different contact numbers

For example
support department employees have home number, mobile number and office number
sales department employee can have only office number

Employee_Details table have following columns
companyId, departmentId, employeeId, firstName, lastName (primary key - companyId, departmentId and employeeId ).

Employee_Contact table have following columns
companyId, departmentId, contactTypeId, contactTypeName (primary key - companyId, departmentId and contactTypeId)

Contact_Details table have following columns
companyId, departmentId, employeeId, contactTypeId, areaCode, number
(primary key - companyId, departmentId, employeeId and contactTypeId)

What will be the best way to map these tables in an entity which can include
employee firstName, lastName and a collection of contact details which include contactTypeName, areaCode, number

The database design is a bit weird, however it cant be changed and I have to work with it.


Top
 Profile  
 
 Post subject: Re: Mapping multiple tables with composite key to single entity
PostPosted: Sun Aug 08, 2010 11:51 pm 
Newbie

Joined: Sat Aug 07, 2010 9:53 am
Posts: 3
Any one ?? Please help


Top
 Profile  
 
 Post subject: Re: Mapping multiple tables with composite key to single entity
PostPosted: Mon Aug 09, 2010 1:03 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hello njks,

You can use <subselect> and have a snapshot of the columns you need. the columns in turn can be mapped in the same hibernate file.

ex:

<hibernate-mapping>
<class name="x.y.z.Rntity"
table="person"
entity-name="z.Rnttiy">
<subselect>
select emp.name name,
dept.name deptname
from employees e,departmenets d
where e.deptid=d.id(+)
</subselect>

<property name="personName"
column="name"
type="string"/>

hope this helps .

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Mapping multiple tables with composite key to single entity
PostPosted: Tue Aug 10, 2010 12:29 am 
Newbie

Joined: Sat Aug 07, 2010 9:53 am
Posts: 3
Thanks I will give it a try :)


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.