aspose file tools*
The moose likes Object Relational Mapping and the fly likes How to create .hbm.xml file for this table? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to create .hbm.xml file for this table?" Watch "How to create .hbm.xml file for this table?" New topic
Author

How to create .hbm.xml file for this table?

saravanan sambandam
Ranch Hand

Joined: Aug 30, 2010
Posts: 42
User Table

create table users(user_id integer, user_name varchar(50), primary key(user_id));

create table group_master(group_id integer, group_name varchar(50), primary key (group_id));

create table user_group (user_group_id integer, group_id integer, user_id integer, foreign key(group_id) references group_master(group_id),
foreign key(user_id) references users(user_id));

in my DB grid i want to display like this

--------------------------------------------------------------------------------------------------------------------------------------
user_group_id | Group_name (group_id will be hidden) | user_name (user_id - will be hidden)
--------------------------------------------------------------------------------------------------------------------------------------

1 | Admin | saravanan
2 | student | kamal
3 | enduser | malar

Getting throug SQL statement

SELECT UG.USER_GROUP_ID, G.group_id, G.GROUP_NAME, a.user_name FROM USER a inner join user_group ug
on ug.user_id = a.id INNER JOIN GROUP_master G ON G.GROUP_ID=UG.GROUP_ID order by UG.USER_GROUP_ID;


But how i will get the same result through HQL Query?
and How i will write .hbm file?
what are the POJO classes are required to get the above result.
How many POJO classes are required?

If any one knows please help me with little details.

Because. i new to hibernate with struts, i was put up under the time estimated time line.

Please, please, help me.

Thanks
saran.
Ravi C Kota
Ranch Hand

Joined: Jan 29, 2008
Posts: 61
Saravanan,

Please read through Hibernate associations for this. The examples given in these docs are very clear and should be helpful. Specifically look for "Bidirectional associations with join tables" section 7.5. You will create only two POJOS.


Thanks & Regards, Ravi C.Kota
SCJP 5.0, OCDJWS 5.0
 
Consider Paul's rocket mass heater.
 
subject: How to create .hbm.xml file for this table?