简体   繁体   中英

Hibernate mapping Object for Inner join query

I'm trying to execute a query that has multiple inner joins and get different columns from these tables.

For ex:

Table-1
    Col1, Col2........Col10


Table-2
    Col1....Col5

Table-3
    Col1...............Col20

Inner join

Select tb1.col1, tb1.col2, tb1.col3, tb2.col1, tb3.col1, tb.col2
inner join
tb1
inner join
tb2
inner join
tb3
where cond1  &cond2

The query executes fine using hibernate but I want the resultset to be mapped to a Java POJO Object..How can I build the mapping Object, Is there any tool that I can use to generate the mapping object for this query...

I can do it manually but there are 40 columns in the output...

Suppose that the three tables correspond to three objects in your model. You can then think of the way that these three objects are associated with each other and which one of these objects will be a natural owner of the relationships. So if you think of object A having a collection of object B which has a collection of object C then you can say that object A owns the relationship.

Then you want your query to return a list of object A.

So you can write:

"SELECT a FROM A a JOIN a.bs b JOIN b.cs c WHERE a.attr = val and b.attr2 = val2"

Since your collection of A will have access to all B and all C then that should satisfy what you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM