获取错误:平台DatabasePlatform不支持​​NativeSequence

时间:2017-01-24 11:59:08

标签: java jpa junit eclipselink spring-batch

我正在尝试为Java Spring批处理应用程序DAO层编写junit测试用例。当我使用自定义序列生成器配置数据层对象,并运行测试用例时,我得到以下异常。

异常说明:SEQ_EMPLOYEE_ID:平台DatabasePlatform不支持​​NativeSequence。

对于数据持久性我正在使用JPA + EclipseLink。

下面提到了我用于Junit的配置文件。

DO类

@Entity
@Table(name = "EMPLOYEE")
@NamedQuery(name = "test.test",
        query = "SELECT d FROM EmployeeDO d where d.status = 'COMPLETED'")
public class EmployeeDO implements Serializable {
    private static final long serialVersionUID = 1L;

    @SequenceGenerator(name = "employeeIdSequence", allocationSize = 1,
            sequenceName = "SEQ_EMPLOYEE_ID")
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "employeeIdSequence")
    @Column(name = "BATCH_ID")
    private long batchId;

}

JunitPersistence.xml

persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
    <persistence-unit name="eclipseLinkPunitEmployee" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

        <class>org.batch.model.data.EmployeeDO</class>

        <exclude-unlisted-classes>true</exclude-unlisted-classes>
          <properties>
            <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:dataSource"/>
            <property name="javax.persistence.jdbc.user" value="sa"/>
            <property name="javax.persistence.jdbc.password" value=""/>
            <property name="eclipselink.ddl-generation" value="create-tables"/>
            <property name="eclipselink.id-validation" value="NULL"/>
        </properties>
    </persistence-unit>
</persistence>

测试上下文XML

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

  <bean id="entityManagerFactory"   class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="eclipseLinkPunitEmployee" />
    <property name='dataSource' ref='junitDatasource' />
    <property name="persistenceXmlLocation" value="classpath:JunitPersistence.xml" />
    <property name="jpaPropertyMap">
        <map>
            <entry key="eclipselink.weaving" value="false" />
        </map>
    </property>
  </bean>  
  <jdbc:embedded-database id="junitDatasource" type="HSQL">
    <jdbc:script location="classpath:sequences.sql"/>
  </jdbc:embedded-database>

sequences.sql

CREATE SEQUENCE SEQ_EMPLOYEE_ID START WITH 1 increment by 1;
CREATE TABLE DUAL (DUMMY DECIMAL);
INSERT INTO DUAL VALUES(1);
SET DATABASE SQL SYNTAX ORA TRUE;

1 个答案:

答案 0 :(得分:1)

本机序列对象特定于正在使用的数据库 - 您需要指定应该用于本机序列的正确数据库平台。如果数据库没有从Spring中获取或设置,则需要添加target-database持久性属性来指定数据库。