开发者

Subselect, joins and O/R mapping

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).

Thanks i开发者_如何学运维n advance.


As i guessed the tuples are returned as objects. Hence for A-Id 222 the B_mod is set as 2121. I used row_num() function to get distinct row nums for each row and used it as a primary key column to get all the rows. This may not be an exact solution but still it worked :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜