JPA在插入时缺少Shema [英] jpa missing shema on insert
问题描述
当我尝试使用item.persist()
时,它失败了.虽然我看不到最终的sql语句,
在绑定参数和架构丢失之前,它确实显示了调用.
创建实体管理器时,我使用的是属性图方法.
因此,也许我使用了错误的属性名称,我正在Web上的各种示例中工作.
我正在使用EclipseLink并访问Netezza数据库.
创建EntityManager
之后,这是getProperties()
的输出:
When I attempt to use item.persist()
,it is failing. While I cannot see the final sql statement,
it does show the call before binding the parameters and the schema is missing.
When I am creating the Entity Manager I am using the map of properties approach.
So, perhaps I am using the wrong property name, I am working from various examples on the web.
I am using EclipseLink and accessing a Netezza database.
After I create the EntityManager
, here is the output from getProperties()
:
em属性:
{javax.persistence.jdbc.url=jdbc:netezza://server.com:5480/databaseName, javax.persistence.jdbc.password=xxxx, openjpa.jdbc.Schema=RT, javax.persistence.jdbc.driver=org.netezza.Driver, javax.persistence.jdbc.user=xxxx}
openjpa.jdbc.Schema=RT
在属性中设置为正确的值.
The openjpa.jdbc.Schema=RT
is set to the right value in the properties.
已更新: 我的persistence.xml中还有以下值:
UPDATED: I also have the following values in my persistence.xml:
<properties>
<property name="openjpa.jdbc.Schema" value="RT" />
<property name="javax.persistence.jdbc.url" value="jdbc:netezza://server.com:5480/database"/>
<property name="javax.persistence.jdbc.user" value="xxxxx"/>
<property name="javax.persistence.jdbc.password" value="xxxx"/>
<property name="javax.persistence.jdbc.driver" value="org.netezza.Driver"/>
</properties>
该模式的正确属性是什么?建议的任何属性中均未列出.需要找到正确的表格...
What is the correct property for the schema? That is not listed in any of the properties suggested. It is required to find the correct table...
推荐答案
openjpa.jdbc.Schema属性仅适用于OpenJPA实现,而不适用于eclipselink. JPA中指定架构的标准方法是使用@Table
批注的架构属性对每个实体进行分配.或者,如果需要为所有实体指定它,则除了创建persistence.xml之外,还可以创建一个其他映射文件,您可以在其中定义XML的默认架构:
The property openjpa.jdbc.Schema works only with OpenJPA implementation,definitely not with eclipselink. Standard way in JPA to specify schema is either per each entity using schema property of@Table
annotation. Or if you need to specify it for all entities, you create an additional mapping file besides persistence.xml, where you may define default schema in XML:
persistence.xml:
persistence.xml:
...
<persistence-unit name="MySchemaPU" transaction-type="JTA">
<mapping-file>META-INF/orm.xml</mapping-file>
以及META-INF文件夹中的新文件orm.xml:
And new file orm.xml in META-INF folder:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
version="1.0">
<persistence-unit-metadata>
<persistence-unit-defaults>
<schema>RT</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings
这篇关于JPA在插入时缺少Shema的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!