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.