1

当我尝试使用 Datanucleus 访问 Oracle 数据库时,我遇到了一个奇怪的问题。简而言之,发生的事情是这样的:

  • 我运行我的应用程序;当 datanucleus 初始化时,它抱怨它找不到表(尽管它们在那里)。
  • 我停止应用程序,删除表格,添加

    datanucleus.autoCreateSchema = true
    

    ...persistence.xml 中的属性,一切正常 - 创建表,然后选择工作。

  • 我再次停止应用程序,然后尝试在禁用上述参数的情况下启动它。

  • 尽管最初是 Datanucleus 创建了表,但错误又回来了,现在它抱怨找不到它们。
  • 另请注意,相同的设置适用于后面的 postgresql 数据库,没有问题。

有人可以帮忙吗?

关于我的设置的一些细节:

  • 我正在使用 Oracle 瘦驱动程序。
  • 我的实体类是这样注释的:

    @Entity
    @Table(name = "tablename1", schema = "schema2000")
    
  • 请注意,如果我从注释中删除 schema=... 一切正常

  • 错误信息是:

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

1 回答 1

4

建议您仔细查看标识符的区分大小写。DataNucleus 记录 JDBC 驱动程序允许的内容,例如

支持的标识符大小写:“MixedCase”大写“MixedCase-Sensitive”

所以它可能需要大写或引用的模式(所有 RDBMS 都是不同的,包括一些不同取决于它们运行的​​操作系统)

显然不建议在注释中嵌入特定于数据存储的信息。

于 2012-12-10T10:39:17.663 回答