The remaining elements of the array are returned as null when querying the collection after applying the batch size. For example, if the batch size is 100 and only 1 id is entered, 99 nulls are bound.Below is the example code
@Entity
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@ManyToOne
@JoinColumn(name = "team_id")
private Team team;
protected Member() {
}
public void setId(Long id) {
this.id = id;
}
public void setTeam(Team team) {
this.team = team;
}
public Long id() {
return id;
}
public Team team() {
return team;
}
}
@Entity
public class Team {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@OneToMany(mappedBy = "team")
private List<Member> members = new ArrayList<>();
public void addMember(Member member) {
members.add(member);
}
public Long id() {
return id;
}
public List<Member> members() {
return members;
}
}
@Transactional
@SpringBootTest
class MemberTest {
@Autowired
private EntityManager em;
@Test
void error() {
Team team = new Team();
em.persist(team);
em.flush();
Member member = new Member();
member.setTeam(team);
em.persist(member);
em.flush();
em.clear();
Team team1 = em.find(Team.class, 1L);
System.out.println(team1.members().size());
}
}
application.yml
logging: level: root: info
org.hiberante.SQL: debug
org.hibernate.orm.jdbc.bind: trace
org.apache.coyote.http11: debug
spring: datasource: driver-class-name: org.h2.Driver
url: jdbc:h2:mem:testdb
username: sa
password:
h2:
console: enabled: true
path: /h2-console
jpa: show-sql: true
open-in-view: false
database-platform: org.hibernate.dialect.H2Dialect
properties: hibernate: format_sql: true
use_sql_comments: true
highlight_sql: true
default_batch_fetch_size: 100
hibernate: ddl-auto: create
and below is error log image.
|