aspose file tools*
The moose likes Object Relational Mapping and the fly likes Retriving data from two tables where there is no physical relation ship in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Retriving data from two tables where there is no physical relation ship in hibernate" Watch "Retriving data from two tables where there is no physical relation ship in hibernate" New topic
Author

Retriving data from two tables where there is no physical relation ship in hibernate

ashok bhemireddy
Greenhorn

Joined: Jan 19, 2011
Posts: 6

I have two tables HEADER and DESCRIPTION. description id is one of the non key column in the table HEADER and which is part of primarykey along with language id in DESCRIPTION. How do I need map this in Header.hbm.xml file to support CRUD operations. Please provide solution if any body faced the similar situation.
Ganesh Shirsat
Ranch Hand

Joined: Jan 10, 2010
Posts: 33

Hi,
Will you please expose the Class or table structure of Header and Description table.?
and what exactly you want from both table.

Thanks
Ganesh Shirsat
ashok bhemireddy
Greenhorn

Joined: Jan 19, 2011
Posts: 6

HEADER
---------
HeaderId,
headerName,
headerType,
descriptionId

HeaderId is primary key

Description
-------------
languageId
descriptionid
description

languageId and headerId are composite primary key.

I want to perform CRUD opeartions on these two tables throgh HEADER.

I want to retrive all decriptions for particular header and manage lifecycle of description from header.
Note: We dont have any physical relationship exist between these two tables.
ashok bhemireddy
Greenhorn

Joined: Jan 19, 2011
Posts: 6

Ok got solution but still one issue is pending...

we can acheive this by using following mapping in Header.hbm.xml


I am able to save and retrive, update in one hibernate save/get/update operation but delete is not working.
When I tried to delete it is trying to update DescriptionId as a null in DESCRIPTION table where DescriptionId is part of the primarykey. AS a work around I have written one native sql query to delete DESCRIPTION records. I am looking for better solution to delete descriptions along with header object in one hibernate call.
ashok bhemireddy
Greenhorn

Joined: Jan 19, 2011
Posts: 6

In this scenario if the parent HEADER has a composit key we are getting the following exception.


This approch works fine when we have single primary key where as it is throwing class cast exception when we have composit key. Please advicse if any body has come across this scenario.
 
Consider Paul's rocket mass heater.
 
subject: Retriving data from two tables where there is no physical relation ship in hibernate