【发布时间】: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