【问题标题】:autocreate schema with jdo, spring and H2 with datanucleus使用 jdo、spring 和 H2 和 datanucleus 自动创建模式
【发布时间】:2014-10-24 20:21:32
【问题描述】:

我最近迁移到使用 DI 的 spring 框架 - 工作正常。我正在注入一个也可以正常工作的持久性管理器。在新安装时,我得到:

SEVERE: Required table missing .... Either your MetaData is incorrect, or you need to enable "datanucleus.autoCreateTables"

很公平,我没有启用自动创建表。

我根据文档在 spring context.xml 中创建我的持久性管理器:

 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="org.h2.Driver"/>
        <property name="url" value="jdbc:h2:./thedbpath.db;MV_STORE=FALSE;MVCC=FALSE;FILE_LOCK=NO"/>
        <property name="username" value=""/>
        <property name="password" value=""/>

    </bean>

    <bean id="pmf" class="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" destroy-method="close">
        <property name="connectionFactory" ref="dataSource"/>
        <property name="nontransactionalRead" value="true"/>

    </bean>

一切正常 - 但我不知道在哪里设置 datanucleus.autoCreateTables

这通常会在persistence.xml 中设置——我看不到将datanucleus 属性放在spring context.xml 中的什么位置。提前致谢

编辑:感谢下面的答案,这是正确的配置:

<bean id="pmf" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
        <property name="jdoProperties">
            <props>
                <prop key="javax.jdo.PersistenceManagerFactoryClass">
                    org.datanucleus.api.jdo.JDOPersistenceManagerFactory
                </prop>
                <prop key="javax.jdo.option.ConnectionURL">jdbc:h2:./database/db;MV_STORE=FALSE;MVCC=FALSE;;FILE_LOCK=NO</prop>
                <prop key="javax.jdo.option.ConnectionUserName">sa</prop>
                <prop key="javax.jdo.option.ConnectionPassword"></prop>
                <prop key="javax.jdo.option.ConnectionDriverName">org.h2.Driver</prop>
                <prop key="org.jpox.autoCreateSchema">true</prop>
                <prop key="org.jpox.identifier.case">PreserveCase</prop>
                <prop key="datanucleus.autoCreateTables">true</prop>
            </props>
        </property>
    </bean>

【问题讨论】:

    标签: spring h2 jdo datanucleus


    【解决方案1】:

    这个页面 http://www.datanucleus.org/products/accessplatform_3_0/guides/jdo/springframework/index.html 有一个“jdoProperties”属性,可用于指定特定于 JDO 实现的属性。可以试试吗?

    【讨论】:

    • 感谢 Neil - 上面的文档有点过时,但底部的示例让我得到了正确的配置。我更新了我的帖子并将其作为答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多