我最近迁移到使用弹簧框架进行DI - 工作正常。我正在注入一个也能正常工作的持久性管理器。在新安装中,我得到:
SEVERE: Required table missing .... Either your MetaData is incorrect, or you need to enable "datanucleus.autoCreateTables"
很公平,我没有启用autocreate表。
我按照doc:
在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中设置 - 我没有看到在spring context.xml中放置datanucleus属性的位置。提前致谢
编辑:感谢下面的答案,这是正确的配置:
<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>
答案 0 :(得分:1)
此页面 http://www.datanucleus.org/products/accessplatform_3_0/guides/jdo/springframework/index.html 有一个&#34; jdoProperties&#34;可用于指定JDO实现特定属性的属性。也许试试吧?