为什么JPA / Spring不在Oracle DB上创建序列

时间:2013-05-21 20:54:26

标签: java spring oracle hibernate jpa

我正在使用JPA将Hibernate支持的实体框架实现为ORM,以便与Oracle DB一起使用。

所有东西都与Spring粘合在一起(自动装配)。

要生成数据库模式,我已将其添加到jpa-context.xml

<bean id="h8JPAVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="showSql" value="false" />
        <property name="generateDdl" value="true" />
</bean>

我已经使用序列生成器为实体生成ID,但出于某种原因,当架构被创建\更新时,Hibernate不会自己创建序列。

这是我的mapping.xml文件,它注入了标识字段

<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
    version="1.0">

    <mapped-superclass class="com.myapp.entity.BaseModelEntity" access="FIELD">
        <attributes>
            <id name="id">
                <generated-value strategy="SEQUENCE" generator="MODEL_SEQ"/>
                <sequence-generator name="MODEL_SEQ" sequence-name="MYAPP_MODEL_SEQ"/>
            </id>
        </attributes>
    </mapped-superclass>
</entity-mappings>

搜索Google总是会给我如何使用现有序列的结果,但我希望Hibernate能够从我这里创建它们。

提前感谢您的帮助

0 个答案:

没有答案