2

My Spring Boot 2 / Hibernate 5 application is running some integration tests against the H2 server version 1.4.197.

What kind of auto increment is the database server using ?

  • a table keeping a number, global to all tables
  • an 'hibernate_sequence' sequence, global to all tables ?
  • some auto increment column, one for each table ?
  • some native sequences, one for each table ?

UPDATE: Following the comments, here is the Hibernate annotations configuration:

@MappedSuperclass
public abstract class AbstractEntity {

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_native")
  @GenericGenerator(name = "id_native", strategy = "native")
  @Column(name = "id", updatable = false, nullable = false)
  private Long id;
...
}

@Entity
@SequenceGenerator(name = "id_generator", sequenceName = "user_role_id_seq")
public class UserRole extends AbstractEntity {
...
}

And the connection parameters:

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.datasource.driver-class-name=net.sf.log4jdbc.DriverSpy
spring.datasource.url=jdbc:log4jdbc:h2:file:./target/useraccounttest;DB_CLOSE_ON_EXIT=FALSE;IGNORECASE=TRUE
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.show-sql=true

Note that the user_role_id_seq sequence is there only to be used by the Oracle database, and is hopefully ignored by the H2 database.

Stephane
  • 11,836
  • 25
  • 112
  • 175
  • 1
    What @a_horse_with_no_name is saying is it's nothing to do with the database, it's what you configured in hibernate, i.e. what you have in your GeneratedValue annotation that will decide. – Essex Boy Jun 29 '18 at 15:07
  • I added the configuration. – Stephane Jun 29 '18 at 15:26

0 Answers0