According to logs Hibernate batch insert doesn't work

I use hibernate 5.4.15.Final with H2. And I want to use batch insert.

This is my entity:

@Entity
@Table(name = "PERSON")
public class Person {

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "NAME")
    private String name;

    //+ getters/setters
}

This is persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.2"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
  <persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.foo.hibernate.h2.test3.Person</class>
    <properties>
      <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:h2:tcp://localhost/mem:db;DATABASE_TO_UPPER=TRUE;TRACE_LEVEL_FIle=0"/>
      <property name="javax.persistence.jdbc.user" value=""/>
      <property name="javax.persistence.jdbc.password" value=""/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
      <property name="hibernate.jdbc.batch_size" value="50"/>
      <property name="hibernate.order_inserts" value="true"/>
      <property name="hibernate.order_updates" value="true"/>
      <property name="hibernate.batch_versioned_data" value="true"/>
    </properties>
  </persistence-unit>
</persistence>

This is my code:

EntityManager manager = factory.createEntityManager();
manager.getTransaction().begin();

Person person1 = new Person();
person1.setName("PersonName1");
manager.persist(person1);

Person person2 = new Person();
person2.setName("PersonName2");
manager.persist(person2);

manager.flush();
manager.clear();

manager.getTransaction().commit();
manager.close();

This is logging config:

<Configuration>
    <Appenders>
        <Console name="Console-Appender" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="org.hibernate" level="debug" additivity="false">
            <AppenderRef ref="Console-Appender"/>
        </Logger>
        <Root level="info">
            <AppenderRef ref="Console-Appender"/>
        </Root>
    </Loggers>
</Configuration>

However, in logs I don’t see anything like (taken from tutorial)

[DEBUG] [main] AbstractBatchImpl - Reusing batch statement
[DEBUG] [main] SQL - insert into PERSON (ID, NAME) values (null, ?)
[DEBUG] [main] BatchingBatch - Executing batch size: 50

What I see is:

[DEBUG] [main] org.hibernate.engine.transaction.internal.TransactionImpl - begin
[DEBUG] [main] org.hibernate.engine.spi.ActionQueue - Executing identity-insert immediately
[DEBUG] [main] org.hibernate.SQL - insert into PERSON (ID, NAME) values (null, ?)
[DEBUG] [main] org.hibernate.id.IdentifierGeneratorHelper - Natively generated identity: 1
[DEBUG] [main] org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl - HHH000387: ResultSet's statement was not registered
[DEBUG] [main] org.hibernate.engine.spi.ActionQueue - Executing identity-insert immediately
[DEBUG] [main] org.hibernate.SQL - insert into PERSON (ID, NAME) values (null, ?)
[DEBUG] [main] org.hibernate.id.IdentifierGeneratorHelper - Natively generated identity: 2

Could anyone say if batch is used and if not how to fix it? Full test project is here (mvn install).

You can’t use strategy = GenerationType.IDENTITY with batch inserts, because identifier is not known before execution of insert statement. Use another strategy.