Duplicate schema name in sequence generation

空扰寡人 提交于 2020-01-11 13:27:29

问题


To prevent the usage of the schema attribute in the table annotation to all of my entities, I set the default schema name by the 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>

And I set it as a mapping file in the 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>

The ID definiation in my entity:

@Entity
@SequenceGenerator( name = "SEQ_Y", sequenceName = "SEQ_Y" )
public class Y implements Serializable
{
  @Id
  @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "SEQ_Y" )
  private int id;
  ...
}

When I try to deploy the application I get this error message:

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

The schema name (X) is duplicated in then SQL statement. How could I fix this?

I have read something about the "TableSequence.java" on an Eclipse forum. (https://www.eclipse.org/forums/index.php/t/798163/) But what is this? Where is this?

This is the same with @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))

来源:https://stackoverflow.com/questions/35834001/duplicate-schema-name-in-sequence-generation

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