• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Mapping same POJO to two tables in Hibernate XML mapping files

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Sreekanth Mogullapally
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic