This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
please anyone can tell me..how to join 2 table in hibernate??
example i want to execute this query --------------------------------------------------- select * from table Employee e,Departments d where e.depid=d.depid --------------------------------------------------
Originally posted by Paul Sturrock: What you've got looks like it should work. What is going wrong?
I think the query he posted was SQL.
select * from table Employee e,Departments d where e.depid=d.depid
So lets say you have an Employee and a Department object. What is the relationship. is it one to many, many to one, etc.
Lets just assume a Department has many Employees, but an Employee has only one Department. So Department has a Collection of Employees.
In Java the Ids should be called id, and not depid, and we are going to assume you mapped the "id" attribute to your actual PK fields in the database
so your HQL query would be
select d from Employee e, Department d where e.id=d.id
See not much different than you SQL, but in Objects. You only need to "select d" to get a List of Departments. I believe, but not positive, that the Employees Collections should also be populated.
And I think there are two types of mappings one to one - one employee works in only one department one to many - one department has many employees.
I think you will find the relationship for employee to department should be many-to-one. For many employees may work in one department. Your one-to-one relationship indicates that only one employee works in one department (in other words, each department has only one employee)
Originally posted by Reehan Lalkhan: I hope the Ranchers read this and include my name in the prize winners list.
Unfortunately, posts that are not on topic will not be included. If you want your post to be considered for the draw, you need to ask a genuine question or answer a question for another rancher.
Mapping is real easy, I let Hibernate or most ORMs use their defaults and I am good.
Mark
Rodrigo Lopes
Ranch Hand
Joined: Feb 29, 2008
Posts: 118
posted
0
Ok, Mark, I got your point. But when you wrote that "In Java the Ids should be called id, and not depid", it sounded that it's mandatory, while it's not.