datanucleus + jpa + oracle. Strange error with tables not existing

喜你入骨 提交于 2019-12-11 08:58:21

问题


I have a strange issue when I try to use Datanucleus to access an Oracle database. In short, what happens is this :

  • I run my application; when datanucleus initializes, it complains that it cannot find the tables (although they are in there).
  • I stop the application, I drop the tables, I add the

    datanucleus.autoCreateSchema = true
    

    ...property in persistence.xml, and everything works - tables are created and then the select works.

  • I stop the application again, and then I try to start it with the above parameter disabled.

  • The error comes back although it was Datanucleus who created the tables in the first place, and now it complains it can't find them.
  • also please note that the same setup works with a postgresql database behind, without issues.

Can somebody please help ?

A few details about my setup :

  • I'm using Oracle thin driver.
  • My entity classes are annotated like this :

    @Entity
    @Table(name = "tablename1", schema = "schema2000")
    
  • Please note that everything works OK if I remove the schema=... from annotation

  • Error message is :

    16:05:40,216 DEBUG [DataNucleus.Connection] - Setting autocommit=false to connection: com.mchange.v2.c3p0.impl.NewProxyConnection@1dff2e1b
    16:05:40,216 DEBUG [DataNucleus.Connection] - Connection "com.mchange.v2.c3p0.impl.NewProxyConnection@1dff2e1b" opened with isolation level "read-committed"
    16:05:40,904 DEBUG [DataNucleus.Datastore.Schema] - Check of existence of schema2000.tablename1 returned table type of null
    16:05:40,905 DEBUG [DataNucleus.Datastore.Schema] - An error occurred while auto-creating schema elements - rolling back
    16:05:41,109 DEBUG [DataNucleus.Connection] - Connection "com.mchange.v2.c3p0.impl.NewProxyConnection@1dff2e1b" non enlisted to a transaction is being committed.
    16:05:41,110 DEBUG [DataNucleus.Connection] - Connection "com.mchange.v2.c3p0.impl.NewProxyConnection@1dff2e1b" closed
    javax.persistence.PersistenceException: Required table missing : "schema2000.tablename1" in Catalog "" Schema "schema2000". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.autoCreateTables"
    at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:274)
    at org.datanucleus.api.jpa.JPAEntityManager.merge(JPAEntityManager.java:519) 
    

回答1:


Suggest you look closer at case-sensitivity of your identifiers. DataNucleus logs what the JDBC driver allows with a line like

Supported Identifier Cases : "MixedCase" UPPERCASE "MixedCase-Sensitive"

so possibly it requires the schema in UPPERCASE or maybe quoted (all RDBMS are different, and inclusive some differ depending on the operating system they're running on)

Obviously embedding datastore-specific info in annotations is not recommended.



来源:https://stackoverflow.com/questions/13764904/datanucleus-jpa-oracle-strange-error-with-tables-not-existing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!