We use @OneToManyfor our relationship parent-> child-> child-> child DB:
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "THE_ID", nullable = false )
private List<ChildClass> children = new ArrayList<ChildClass>();
We have a scenario with a lot of data (100K inserts) where the startup performance is terrible (actually time out). With a small amount of data (1K inserts) we are nonetheless good.
So for good reason, I deleted nullable = falseand changed the DB foreign key on the child tables to allow a null value, and the preliminary performance is not bad. Can anyone explain this?
Update . Debugging enabled. Since nullable = falsethere is a huge bottleneck, generating IDs for child tables. We are waiting for a timeout to generate identifiers, with this in the log again and again:
[org.hibernate.event.def.AbstractSaveEventListener] [ ] generated identifier: <743088>, using strategy: org.hibernate.id.IncrementGenerator
We can’t even insert data into the database. We just get hung up on id gen. We are currently setting up Hibernate to generate identifiers by looking at the maximum id values currently in the child table:
@Id
@GeneratedValue(generator = "DummyString")
@GenericGenerator(name = "DummyString", strategy = "increment")
@Column(name = "THE_ID", nullable = false)
private Long id;
Before that, we used the database sequence and saw the same problems.
When we omit nullable = false, we see these ID gen statements (108K of them), but they end in 25 seconds. So why do these statements (literally) take forever nullable = false?