Batch Fetching stops working when I enable bytecode enhancement.
I'm using hibernate-enhance-maven-plugin for build time enhancement.
I used reflection at the Test case, is there a better way to validate this issue?
{code:java} @Entity public class Team { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @OneToMany(mappedBy="team") private List<Member> members; {code} {code:java} @Entity public class Member { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; private String name; @ManyToOne @JoinColumn(name="team_id") private Team team; {code}
persistence.xml {code:xml} <property name="hibernate.batch_fetch_style" value="DYNAMIC" /> <property name="hibernate.default_batch_fetch_size" value="100" /> {code}
{panel:title=Bytecode Enabled, n+1 problem loading members} Hibernate: /* from Team */ select team0_.id as id1_1_ from Team team0_ Hibernate: /* load one-to-many com.test.entities.Team.members */ select members0_.team_id as team_id3_0_1_, members0_.id as id1_0_1_, members0_.id as id1_0_0_, members0_.name as name2_0_0_, members0_.team_id as team_id3_0_0_ from Member members0_ where members0_.team_id=? (repeats for each team)
{panel}
{panel:title=Bytecode Disabled, Batch Fetching working properly} Hibernate: /* from Team */ select team0_.id as id1_1_ from Team team0_ Hibernate: /* load one-to-many com.test.entities.Team.members */ select members0_.team_id as team_id3_0_1_, members0_.id as id1_0_1_, members0_.id as id1_0_0_, members0_.name as name2_0_0_, members0_.team_id as team_id3_0_0_ from Member members0_ where members0_.team_id in ( ?,?,?,?,?,?,?,?,?,? ) {panel} |
|