0

I have the following database setup using Spring and Hibernate as JPA implementor. I have a entity class extending org.springframework.data.jpa.domain.AbstractPersistable which basically defines an id attribute with a generation strategy of AUTO.

If read everything correctly, this would mean that the JPA implementor, Hibernate in my case, is responsible for generating the id.

It does work for an actual setup using PostgreSQL but not for this embedded setup:

    <jdbc:embedded-database id="dataSource" type="HSQL">
        <jdbc:script location="classpath:/sql/schema.sql" />
    </jdbc:embedded-database>

    <bean
        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect" />
            </bean>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

Entity class

@Entity
public class Account extends AbstractPersistable<Long> {

    private static final long serialVersionUID = 1L;

    @NotNull
    @Size(min=1, max=25)
    private String name;
}
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Jonas Geiregat
  • 5,214
  • 4
  • 41
  • 60

0 Answers0