选择多个@OneToOne实体不会批处理子引用查询

问题描述

我正在尝试加载9个不同的“ Spawns”,它们对它们的位置都有1:1的引用。该位置引用了其“块”。

我认为这可以批量处理1-3个查询,而是休眠加载所有9个生成器,然后为每个位置和每个块触发一个查询...这是很多方法。

@MappedSuperclass
public class Base{

    @Id
    public long id;

    @OneToOne
    @JoinColumn(name = "identity_id",referencedColumnName = "id")
    @MapsId
    public Identity identity;
}
@Entity
@Table(name = "spawner")
@Access(value = AccessType.FIELD)
public class Spawner extends Base{

   @OneToOne
   @JoinColumn(name = "location_id",referencedColumnName = "identity_id")
   @Fetch(FetchMode.JOIN)
   public Location location;

   public Spawner() { }
}
@Entity
@Table(name = "location")
@Access(AccessType.FIELD)
public class Location extends Base {

    @ManyToOne
    @JoinColumn(name = "chunk_id",referencedColumnName = "identity_id",updatable = false)
    @Fetch(FetchMode.JOIN)
    public Chunk chunk;

    public Location() {}
}

通过:session.createQuery("select s Spawner s where s in(...)")加载它们会抛出此休眠调试输出...

Hibernate: select identity0_.id as id1_2_0_,location1_.identity_id as identity1_6_1_,identity0_.tag as tag2_2_0_,identity0_.typeID as typeid3_2_0_,location1_.chunk_id as chunk_id4_6_1_,location1_.x as x2_6_1_,location1_.y as y3_6_1_ from identity identity0_ inner join location location1_ on (location1_.identity_id=identity0_.id and (identity0_.id in (8326589099709645653,6287325594386187920,5407611297503526929,8523982519594665733,4028725686660451036,4729790674605130415,6901230747306707572,89683718271946391,663547951024983400,487871300966958647,2986281183600263327,7129934223659254130,7423461182852450838,6258927419235452915,4756503673250530721,7989242675644875262,7502164321920434546,9125201177335319448,5276750027792075277,2958385004616501743,8131213851438696494,5378786184839581257,4800722432645154706)))
Hibernate: select chunk0_.identity_id as identity1_0_0_,chunk0_.createdOn as createdo2_0_0_,chunk0_.x as x3_0_0_,chunk0_.y as y4_0_0_,inchunk1_.Chunk_identity_id as chunk_id1_1_1_,identity2_.id as inchunk_2_1_1_,identity2_.id as id1_2_2_,identity2_.tag as tag2_2_2_,identity2_.typeID as typeid3_2_2_ from chunk chunk0_ left outer join chunk_identity inchunk1_ on chunk0_.identity_id=inchunk1_.Chunk_identity_id left outer join identity identity2_ on inchunk1_.inChunk_id=identity2_.id where chunk0_.identity_id=?
Hibernate: select identity0_.id as id1_2_0_,identity0_.typeID as typeid3_2_0_ from identity identity0_ where identity0_.id=?
Hibernate: select chunk0_.identity_id as identity1_0_0_,identity0_.typeID as typeid3_2_0_ from identity identity0_ where identity0_.id=?

如您所见,它为每个加载的“生成程序”触发一个“选择块”查询...为什么会发生?以及我们如何批量处理这些选择呢?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)