Search code examples
springh2jdodatanucleus

autocreate schema with jdo, spring and H2 with datanucleus


I Recently migrated to using the spring framework for DI - working fine. I'm injecting a persistence manager which also works fine. On a new install, I get:

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

Fair enough, I'm not enabling autocreate tables.

I create my persistence manager like this in the spring context.xml per the doc:

 <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>

everything works - but i can't figure out where to set the datanucleus.autoCreateTables

This normally would be set in the persistence.xml - I don't see where to put datanucleus properties in the spring context.xml. Thanks in advance

edit: thanks to the answer below, this was the correct config:

<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>

Solution

  • This page http://www.datanucleus.org/products/accessplatform_3_0/guides/jdo/springframework/index.html has a "jdoProperties" property that can be used to specify JDO implementation-specific properties. Maybe try that?