简体   繁体   English

用于内部联接查询的Hibernate映射对象

[英]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... 使用休眠可以很好地执行查询,但是我希望将结果集映射到Java POJO对象。如何构建映射对象,是否可以使用任何工具为该查询生成映射对象...

I can do it manually but there are 40 columns in the output... 我可以手动完成,但输出中有40列...

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. 因此,如果您想到对象A具有对象B的集合,而对象B具有对象C的集合,那么您可以说对象A拥有关系。

Then you want your query to return a list of object A. 然后,您希望查询返回对象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. 由于您的A集合将可以访问所有B和所有C,因此应该可以满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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