wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Subselect joins 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 "Subselect joins" Watch "Subselect joins" New topic

Subselect joins

deepak tharigopla

Joined: Jun 25, 2011
Posts: 1
i am following struts 2 and hibernate 5. I have two tables A and B with different primary keys A_ID and B_ID. They have common columns like model, name.

In my hbm file, I didnt refer to any of the above tables instead I have a subselect query which joins the two tables.

The mappings in the hbm file is

<id name="a_id" column="A_ID" />

<property name="b_model" column="B_model"/>

When i ran the hibernate query generated. I got the following output in MySql

A_Id B_model other columns
111 3131
222 2121
222 4141
333 5151
But the list returned when the query is executed is

list(0) = 111 and 3131
list(1) = 222 and 2121
list(2) = 222 and **2121**
list(3) = 333 and 5151.
My question is why didnt list(2) didnt have 4141 instead of 2121.

And please let me know what i should to get the same (i.e) i need 4141 in list(2).

I probably guess it is creating one object for the primary key tuple 222 and setting it to the first value 2121. And hence the next value which is also 222 contains the first value 2121. Please confirm this and a possible solution to my problem.

Thanks in advance.
Consider Paul's rocket mass heater.
subject: Subselect joins
Similar Threads
Hibernate Criteria can't create joins for Embedded objects
Many to One instead of One to One relationship
Dynamic SQL in hibernate
Mapping two Hibernate Object based on their foriegn keys
Parent class id value instead of child's id used incorrectly for querying Set assoc.