2011-10-20 46 views
1

我有一个奇怪的效果,即在执行特定的hql查询时,hibernate会触发多个查询。目前我使用hsqldb 1.8进行开发。Hibernate从hql查询中创建多个查询

@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=? 

我想选择所有PointOfInterestLabel给定的数字。因此,连接两个表应该足够了。

图:

public class Figure { 
    @OneToMany(mappedBy = "figure") 
    private List<PointOfInterest> pois = new ArrayList<PointOfInterest>(); 

PointOfInterest:

public class PointOfInterest extends GenericEntity { 
    @ManyToOne 
    @JoinColumn(name="figureId", nullable=false) 
    private Figure figure; 

    @OneToMany(mappedBy="poi") 
    private List<PointOfInterestLabel> labels = new ArrayList<PointOfInterestLabel>(); 

PointOfInterestLabel:

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

    @Id 
    @GeneratedValue 
    private long id; 

    @ManyToOne 
    @JoinColumn(name="pointOfInterestId") 
    private PointOfInterest poi; 

那我做错了什么?我只想要一个连接来获得所有PointOfInterestLabel给定的数字。

问候 米

+0

你能给我们PointOfInterestLabel的映射吗? –

+0

当然!问候。 – mkuff

+0

看看http://code.google.com/p/log4jdbc/,看看你是否可以获得准备好的语句参数的实际值,以查看hibernate是否实际上多次创建相同的查询。 –

回答

0

我也有类似的问题。不知道它是否适合你,但无论如何:

Select distinct pl FROM PointOfInterestLabel pl INNER JOIN FETCH pl.poi p WHERE p.figure = :figure

+0

试过了,但没有没有帮助。感谢您的回答。 – mkuff

0

我认为这种情况的原因是联想预先加载。默认情况下,所有ToOne关联都被热切地提取。您可以通过指定fetchType来覆盖它。更改PointOfInterestLabel类如下 - 注意获取属性..

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; 
0

你有两个OneToManyAssociations:一个从图到POI和POI和离题之间的第二。这些都是延迟加载的,因为如果不指定其他任何内容,这些都是默认配置。

你也想要从所有3个对应表中选择数据makinga查询:

Select pl FROM PointOfInterestLabel pl INNER JOIN pl.poi p WHERE p.figure = ? 

“FROM PointOfInteresetLabel”看起来离题表 “pl.poi”看在POI表 “ p.figure“看起来如图

如果您不指定预先获取(无论是在关联配置中,还是在HQL查询中),它们都将使用N + 1选择操作加载,因此生成的许多SQL查询

尝试:

SELECT pointOfInterest FROM Figure AS figure INNER JOIN FETCH figure.pois AS pointOfInterest INNER JOIN FETCH pointOfInterest.labels AS labels WHERE figure=:figure