为了防止在我的所有实体中使用表注释中的schema属性,我通过schema.xml设置了默认模式名称:
<?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 orm_2_0.xsd"
version="2.0">
<persistence-unit-metadata>
<persistence-unit-defaults>
<schema>X</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
我将它设置为persistence.xml中的映射文件:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="SayHello-ejbPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/SayHello</jta-data-source>
<mapping-file>META-INF/schema.xml</mapping-file>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
我的实体中的ID定义:
@Entity
@SequenceGenerator( name = "SEQ_Y", sequenceName = "SEQ_Y" )
public class Y implements Serializable
{
@Id
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "SEQ_Y" )
private int id;
...
}
当我尝试部署应用程序时,收到以下错误消息:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: SEQUENCE 'X.X' does not exist.
Error Code: -1
Call: VALUES(NEXT VALUE FOR X.X.SEQ_Y)
Query: ValueReadQuery(sql="VALUES(NEXT VALUE FOR X.X.SEQ_Y)")
模式名称(X)在SQL语句中重复。我怎么能解决这个问题?
我已经读过关于&#34; TableSequence.java&#34;在Eclipse论坛上。 (https://www.eclipse.org/forums/index.php/t/798163/)但这是什么?这是哪里?
这与@TableGenerator相同:
@Entity
@TableGenerator(
name = "GEN_Y",
table = "ID_GENERATOR",
pkColumnName = "GEN_KEY",
pkColumnValue = "GEN_Y",
valueColumnName = "GEN_VALUE" )
)
public class Y implements Serializable
{
@Id
@GeneratedValue( strategy = GenerationType.TABLE, generator = "GEN_Y" )
private int id;
...
}
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "." at line 1, column 17.
Error Code: -1
Call: CREATE TABLE X.X.ID_GENERATOR (GEN_KEY VARCHAR(50) NOT NULL, GEN_VALUE DECIMAL(15), PRIMARY KEY (GEN_KEY))