0

When using JOINED inheritence strategy hibernate is not ordering inserts and as a result batch inserts are not working. This is causing a performance hit. Is there any way to keep using the strategy and configure hibernate to order the inserts? I have used id generation strategy as sequence so that is not the issue.

As an example say we have abstraction Animal. Dog, Cat etc.. are the concrete entities. Following are the operations.

Animal a = new Dog();
Animal b = new Cat();
save(a);
save(b);

SQL statements in console that are logged.

insert into animal...;
insert into dog...;
insert into animal...;
insert into cat...;

What I expect hibernate to do..

insert into animal...;
insert into animal...;
executing batch of size 2;
insert into dog..;
insert into cat..;
rupesh
  • 109
  • 7
  • Looks like hibernate is working as expected... you save a dog first, which requires an insert to animal and an insert to dog. Then you save a cat, which in turn requires an insert to animal and an insert to cat – XtremeBaumer Apr 08 '22 at 11:12
  • It is true that parent has to be inserted first. But, same is the case with any foreign key relation. I expected that as order_inserts is true, inserts should be rearranged so that batching can be performed. – rupesh Apr 08 '22 at 11:36
  • You are in the same transaction of course. – grigouille Apr 08 '22 at 13:55
  • Duplicate of https://stackoverflow.com/questions/32500406/hibernate-is-batching-disabled-for-single-table-inheritance but it has no answer. I'd suggest looking at single table inheritance, or an alternate provider (I believe EclipseLink supports this level of statement rearranging for batching) – Chris Apr 08 '22 at 18:31

0 Answers0