This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
 
wood burning stoves
 
subject: How to create .hbm.xml file for this table?
 
Similar Threads
Mail Server - Database Design
how to retrieve values from more than two tables
Unknown PK Problem
Mapping same POJO to two tables in Hibernate XML mapping files
Glassfish + jdbcrealm