Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
ashok bhemireddy
Greenhorn
Posts: 6
Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
Google Web Toolkit Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic