我有一个奇怪的效果,即hibernate在执行特定的hql查询时会触发多个查询。目前我使用hsqldb 1.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=?
我想为给定的数字选择所有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 :(得分:0)
我有类似的问题。不确定它是否适合你,但无论如何:
Select distinct pl FROM PointOfInterestLabel pl INNER JOIN FETCH pl.poi p WHERE p.figure = :figure
答案 1 :(得分:0)
我认为造成这种情况的原因是对协会的急切加载。默认情况下,所有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;
答案 2 :(得分:0)
您有两个OneToManyAssociations:一个从图到POI,另一个在POI和POIL之间。这些都是延迟加载的,因为如果你没有指定其他内容,这是这些的默认配置。
您还在进行一项想要从所有3个相应表中选择数据的查询:
Select pl FROM PointOfInterestLabel pl INNER JOIN pl.poi p WHERE p.figure = ?
“FROM PointOfInteresetLabel”在POIL表中查找 “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