wood burning stoves
The moose likes Object Relational Mapping and the fly likes Mapping same POJO to two tables in Hibernate XML mapping files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Mapping same POJO to two tables in Hibernate XML mapping files" Watch "Mapping same POJO to two tables in Hibernate XML mapping files" New topic
Author

Mapping same POJO to two tables in Hibernate XML mapping files

Sreekanth Mogullapally
Greenhorn

Joined: Jul 21, 2010
Posts: 2


I have below two tables. How should i map in a single mapping file withy single POJO Class.

create table Table1 (
id INTEGER NOT NULL,
code varchar(50) not null,
PRIMARY KEY (id)
);

create table Table2(
id INTEGER NOT NULL,
seq_number INTEGER NOT NULL,
description varchar(50) NOT NULL,
PRIMARY KEY (id,seq_number),
foreign key(id) references Table1(id)
);


Please help me in this regard.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You can by specifying the join table

# <class name="Emp" table="EMP">
# <id name="id" column="EMP_ID">...</id>
# ...
# <join table="ADDRESS">
# <key column="EMP_ID"/>
# <property name="addrLine1"/>
# <property name="city"/>
# </join>


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Sreekanth Mogullapally
Greenhorn

Joined: Jul 21, 2010
Posts: 2
Thankx for your quick reply.

But here the problem is the table i need to join is having composite primary key in that one column is referenced to parent table.

How should i mention this composite primary key in join tag?
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Mapping same POJO to two tables in Hibernate XML mapping files
 
jQuery in Action, 3rd edition