Java Hibernate从hql查询创建多个查询

Java Hibernate从hql查询创建多个查询,java,hibernate,jpa-2.0,Java,Hibernate,Jpa 2.0,我有一个奇怪的效果,hibernate在执行特定hql查询时会触发多个查询。目前,我使用HSQLDB1.8进行开发 @NamedQuery(name=PointOfInterestLabel.FIND_BY_FIGURE, query="Select pl FROM PointOfInterestLabel pl INNER JOIN pl.poi p WHERE p.figure = :figure") 控制台输出: Hibernate: select pointofint0_.id as

我有一个奇怪的效果,hibernate在执行特定hql查询时会触发多个查询。目前,我使用HSQLDB1.8进行开发

@NamedQuery(name=PointOfInterestLabel.FIND_BY_FIGURE, query="Select pl FROM PointOfInterestLabel pl INNER JOIN pl.poi p WHERE p.figure = :figure")
控制台输出:

Hibernate: select pointofint0_.id as id5_, pointofint0_.labelId as labelId5_, pointofint0_.locale as locale5_, pointofint0_.pointOfInterestId as pointOfI4_5_ from PointOfInterestLabel pointofint0_ inner join PointOfInterest pointofint1_ on pointofint0_.pointOfInterestId=pointofint1_.id where pointofint1_.figureId=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
Hibernate: select pointofint0_.id as id1_1_, pointofint0_.figureId as figureId1_1_, pointofint0_.percentageX as percenta2_1_1_, pointofint0_.percentageY as percenta3_1_1_, pointofint0_.x as x1_1_, pointofint0_.y as y1_1_, figure1_.id as id2_0_, figure1_.fileName as fileName2_0_, figure1_.height as height2_0_, figure1_.legende as legende2_0_, figure1_.originalFileHash as original5_2_0_, figure1_.svgHash as svgHash2_0_, figure1_.width as width2_0_ from PointOfInterest pointofint0_ inner join Figure figure1_ on pointofint0_.figureId=figure1_.id where pointofint0_.id=?
我想选择给定图形的所有兴趣点标签,所以两个表的连接就足够了

图:

    public class Figure {
    @OneToMany(mappedBy = "figure")
    private List<PointOfInterest> pois = new ArrayList<PointOfInterest>();
那么我做错了什么?我只需要一个连接,以获得给定图形的所有兴趣点标签

问候
我也有类似的问题。不确定它是否适合您,但无论如何:


选择distinct pl FROM pointof interestlabel pl internal JOIN FETCH pl.poi p,其中p.figure=:figure

我认为这是因为急于加载关联。默认情况下,所有ToOne关联都会被急切地获取。您可以通过指定fetchType来覆盖它。如下更改PointOfInterestLabel类-注意fetch属性

public class PointOfInterestLabel extends GenericEntity {
    private static final long serialVersionUID = 969499193403830375L;

    @Id
    @GeneratedValue
    private long id;

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="pointOfInterestId")
    private PointOfInterest poi;

您有两个onetomanyassociation:一个从Figure到POI,另一个在POI和POIL之间。这些都是延迟加载的,因为如果不指定任何其他内容,这是它们的默认配置

您还进行了一个查询,希望从所有3个对应表中选择数据:

Select pl FROM PointOfInterestLabel pl INNER JOIN pl.poi p WHERE p.figure = ?
“从PointOfInterestLabel”在POIL表中查找 “pl.poi”在poi表中查找 “p.figure”在figure表中显示

如果不指定即时抓取(在关联配置或HQL查询中),将使用N+1选择操作加载它们,因此会生成许多SQL查询

尝试:


你能给我们一些PointOfInterestLabel的映射吗?看看你是否能得到准备好的语句参数的实际值,看看hibernate是否真的多次创建了相同的查询,但是没有帮助。谢谢你的回答。
public class PointOfInterestLabel extends GenericEntity {
    private static final long serialVersionUID = 969499193403830375L;

    @Id
    @GeneratedValue
    private long id;

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="pointOfInterestId")
    private PointOfInterest poi;
Select pl FROM PointOfInterestLabel pl INNER JOIN pl.poi p WHERE p.figure = ?
SELECT pointOfInterest FROM Figure AS figure INNER JOIN FETCH figure.pois AS pointOfInterest INNER JOIN FETCH pointOfInterest.labels AS labels WHERE figure=:figure