Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Hibernate :Mapping Multiple Table for single POJO class(with my problem explanation )

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was trying to translate an SQL query to hibernate. But the problem is with the mapping. I have a class named UserBean to which values from different table is required. So I don�t know how to map this UserBean class, as there is no table in my data base that corresponds to UserBean. The properties in UserBean needs to get values from three tables, named

1. seat_user_alloted

allot_Id (primary,autoincrement),
seat_Id,
user_Id,
active_Date,
deactive_Date,
active_Status,
passwd

2. user_setup

user_Id(primary,autoincrement),
employee_Id,
user_Name,
active_Date,
deactive_Date,
active_Status,
user_Code

3. hierarchy_setup

hierarchy_Id (primary,autoincrement),
hierarchy_Name,
hierarchy_Code,
hierarchy_Level,
parent_hierarchy,
hierarchy_Tree,
active_Date,
deactive_Date,
active_Status,
category,
allot_Status



The query that I need to translate is shown below

select
seat_user_alloted.seat_Id as seatId,
seat_user_alloted.user_Id as userId,
hierarchy_setup.hierarchy_Name as seatName,
hierarchy_setup.hierarchy_Code as seatCode,
user_setup.user_Code as empCode,
user_setup.user_Name as empName
from
user_setup,hierarchy_setup,seat_user_alloted
where
seat_user_alloted.user_Id=user_setup.user_Id
and
seat_user_alloted.seat_Id=hierarchy_setup.hierarchy_Id
and
user_setup.active_Status='Y'
and
hierarchy_setup.active_Status='Y'
and
seat_user_alloted.active_Status='Y'


note: In the select query above� that table-column-values are got in to the UserBean which contains the properties given below with getter and setters.

UserBean
private String seatId;
private String userId;
private String seatName;
private String seatCode;
private String empCode;
private String empName;
private String userOffice;
private String userManager;
private String userSection;

Now how can I map this user bean to three tables� or please some one post a solution.

[ November 19, 2008: Message edited by: Arun G Nair ]
[ November 19, 2008: Message edited by: Arun G Nair ]
 
Ranch Hand
Posts: 162
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Arun,

I think single pojo solution is not possible here.
Hope , following solution will help i your case.

Create pojo for each table like for user_setup create pojo having all column in that table,
same for hierarchy_setup ,
And while creating pojo for seat_user_alloted add object of user_setup pojo
and hierarchy_setup pojo.

So your seat_user_alloted pojo will look like :



Thanks
- Kuldeep
 
Arun G Nair
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well thanks for your suggestion Kuldeep!!! But doing so.. how shall I get values, and to which object I will get that... Actually in ibatis this is not an issue, because we can directly assign the values from different tables to a single class.

But I think, working in hibernate also, this kind of issue will come again and again... so could you please explain the solution in detail, if possible..
 
Arun G Nair
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also please show me how the "hbm.xml" file for my case will look like...
 
Beware the other head of science - it bites! Nibble on this message:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic