This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Kubernetes in Action and have Marko Luksa on-line!
See this thread for details.
Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Subselect joins  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!