Problems with DataNucleus JDO and MS Sql Server 2012


Max Treptow
 

When I try to read data from a very simple database table on the MS Sql Server 2012 by a DataNucleus JDO query, I get the following error message:

 

Exception in thread "main" javax.jdo.JDODataStoreException: Required table missing : "DBO.MSE" in Catalog "" Schema "DBO". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"

 

This is the persistence.xml  file, I use to configure the database connection:

persistence-unit name="RdstTest">
        <properties>

 

            <property name="javax.jdo.option.ConnectionURL" value="jdbc:sqlserver://<db_server>:6201;databaseName=rdst;SelectMethod=cursor"/>

 

            <property name="javax.jdo.option.ConnectionDriverName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>

 

            <property name="javax.jdo.option.ConnectionUserName" value="<user>"/>

 

            <property name="javax.jdo.option.ConnectionPassword" value="<password>"/>

 

            <property name="javax.jdo.mapping.Schema" value="dbo"/>

 

            <property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>

 

        </properties>

 

    </persistence-unit>

 

And this is the O/R class to map the database table:

 

@PersistenceCapable (identityType = IdentityType.DATASTORE, table = "Mse")

 

public class Mse
{
   

    public Mse() {}   

    @Persistent()
    private String _title; 

 

    public String getTitle() {
        return _title;
    }

    public void setTitle(String title) {
        _title = title;
    }
}

 

 

I tested this with several identity types and Id generator strategies and using 2 different software environments:

 

  1. DataNucleus 3, Java 7, Ant, MS Sql Server 2012, mssql-jdbc-6.4.0.jre7.jar

  2. DataNucleus 5, Java 8, Maven, Sql Server 2012, mssql-jdbc-6.1.0.jre8.jar

All tests without success.

 

Additional information:
1. The access to this table (data reading) using Hibernate (Hibernate 4, Java 8, Maven 3, MS Sql Server 2012, mssql-jdbc-6.1.0.jre8.jar) works fine. So I assume connection parameters and user privileges seem to be correct.
2. Data access to an Oracle 10g database with the same DataNucleus versions (3 and 5, Java 7 and 8) works without any problems too.

 

Because the database table exists and I can read the table content using Hibernate, I’m afraid my O/R class for DataNucleus mapper is wrong.
Could you tell me, what else can I try / what else can I do better to get data access on a MS SQL Server?

 

Thank you in advice

 

 

 

 


Andy
 
Edited

Exceptions have stack traces, so post it; they show where the exception came from.
Also the log (DEBUG) tells you what was going on at that point, hence may have some SQL statement, or may be using DatabaseMetaData to check things. If it is SQL then invoke that same SQL yourself directly and see what result you get.

The other thing that the log would show is the CASE supported by the SQLServer JDBC driver, so think whether case sensitivity of the table name is a factor ...


Max Treptow
 

This is the logfile after the enhancing of o/r class Mse.java:

 

The class to get MSE data from the database:

public class MseData {

 

private PersistenceManagerFactory pmf;

private PersistenceManager pm;

 

public static void main( String[] args )

{

MseData mseData = new MseData();

mseData.listMseData2();

}

private void listMseData2() {

 

pmf = JDOHelper.getPersistenceManagerFactory("RdstTest");

pm = pmf.getPersistenceManager();

 

Extent<Mse> tExtent = pm.getExtent(Mse.class, false);

 

Iterator<Mse> mseData = tExtent.iterator();

 

while(mseData.hasNext()) {

 

Mse mse = (Mse) mseData.next();

System.out.println(mse.getTitle());

}

pm.close();

pmf.close();

}

}

The command Extent<Mse> tExtent = pm.getExtent(Mse.class, false);
throws the following exception:

Exception in thread "main" javax.jdo.JDODataStoreException: Required table missing : "DBO.MSE" in Catalog "" Schema "DBO". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"


at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:553)


at org.datanucleus.api.jdo.JDOPersistenceManager.getExtent(JDOPersistenceManager.java:1550)


at eu.jcz.dnt1.app.MseData.listMseData2(MseData.java:30)


at eu.jcz.dnt1.app.MseData.main(MseData.java:22)

 

 

 

NestedThrowablesStackTrace:

 

Required table missing : "DBO.MSE" in Catalog "" Schema "DBO". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"

 

 

org.datanucleus.store.rdbms.exceptions.MissingTableException: Required table missing : "DBO.MSE" in Catalog "" Schema "DBO". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"


at org.datanucleus.store.rdbms.table.AbstractTable.exists(AbstractTable.java:607)


at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.performTablesValidation(RDBMSStoreManager.java:3400)


at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.run(RDBMSStoreManager.java:2911)


at org.datanucleus.store.rdbms.AbstractSchemaTransaction.execute(AbstractSchemaTransaction.java:118)


at org.datanucleus.store.rdbms.RDBMSStoreManager.manageClasses(RDBMSStoreManager.java:1643)


at org.datanucleus.store.AbstractStoreManager.getExtent(AbstractStoreManager.java:987)


at org.datanucleus.ExecutionContextImpl.getExtent(ExecutionContextImpl.java:5209)


at org.datanucleus.api.jdo.JDOPersistenceManager.getExtent(JDOPersistenceManager.java:1546)


at eu.jcz.dnt1.app.MseData.listMseData2(MseData.java:30)


at eu.jcz.dnt1.app.MseData.main(MseData.java:22)

 

The whole logfile datanucleus.log is attached.


Andy
 

As the log shows, your database supports MixedCase datastore identifiers
Supported Identifier Cases : MixedCase "MixedCase" MixedCase-Sensitive "MixedCase-Sensitive"
and it is looking up a table name of "MSE". So have you created the table as that name (in capitals)? because if you haven't then it explains clearly why you get a problem.
Persistence property datanucleus.identifier.case  provides the options you need to control what name it looks up.