简体   繁体   中英

Hibernate creates more than one query from hql query

I am having a strange effect that hibernate fires more than one query when executing a specific hql query. At moment i use hsqldb 1.8 for development.

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

Console Output:

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

I wanted to select all PointOfInterestLabel to the given figure. So a join over two tables should be sufficient.

Figure:

    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;

So what am i doing wrong? I just want a join to get all PointOfInterestLabel to a given figure.

greetings m

I had a similar problem. Not sure if it works for you but anyway:

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

I think the cause of this is eager loading for associations. By default all ToOne associations are eagerly fetched. You can override it by specifying fetchType. Change the PointOfInterestLabel class as follows - note the fetch attribute..

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;

You have two OneToManyAssociations: one from Figure to POI and a second between POI and POIL. These are all lazy-loaded as that's the default config for these if you don't specify anything else.

You're also makinga query that wants to select data from all 3 corresponding tables:

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

"FROM PointOfInteresetLabel" looks in the POIL table "pl.poi" looks in the POI table "p.figure" looks in the figure table

If you don't specify eager fetching (either in the associations config, or in the HQL query), they will be loaded using N+1 Select operations, hence the many generated SQL queries

Try:

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

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