Skip to content
Advertisement

JPA/EclipseLink Error in Creating Tables

I am trying to create a table using EclipseLink. The java class being used is :-

import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Id;

@Entity
public class Submissions {

 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Long Id;
 private String XID;
 private String Y;
 @Temporal(TemporalType.DATE)
 private Date uDate;
 private String level;
 private String state;

 public Submissions() {
 }

 //All Relevant getter and setter functions
}

The relevant persistence xml in question is as follows:-

<persistence-unit name="SubmissionIds">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.obp.selenium.DataObjects.OriginationSubmissions</class>
    <properties>

        <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
        <property name="javax.persistence.jdbc.url"
            value="jdbc:oracle:thin:@localhost:1521:orcl" />
        <property name="javax.persistence.jdbc.user" value="------" />
        <property name="javax.persistence.jdbc.password" value="------" />

        <!-- EclipseLink should create the database schema automatically -->
        <property name="eclipselink.ddl-generation" value="create-tables" />
        <property name="eclipselink.ddl-generation.output-mode"
            value="database" />
        <!-- <property name="eclipselink.canonicalmodel.subpackage"
            value="originationSubmissions" /> -->
    </properties>
</persistence-unit>

We use the standard method is by implementing the EntityManagerFactory as :-

EntityManagerFactory factory = Persistence.createEntityManagerFactory("SubmissionIds");
    EntityManager em = factory.createEntityManager();
    em.getTransaction().begin();
    em.getTransaction().commit();
    em.close();

However I keep getting the following errors :-

EL Warning]: 2017-04-07 14:04:53.768–ServerSession(1650327539)–Exception [EclipseLink-4002] (Eclipse Persistence Services – 2.6.3.v20160428-59c81c5): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00904: : invalid identifier

Error Code: 904 Call: CREATE TABLE SUBMISSIONS (ID NUMBER(19) NOT NULL, XID VARCHAR2(255) NULL, Y VARCHAR2(255) NULL, LEVEL VARCHAR2(255) NULL, STATE VARCHAR2(255) NULL, UDATE DATE NULL, PRIMARY KEY (ID)) Query: DataModifyQuery(sql=”CREATE TABLE SUBMISSIONS (ID NUMBER(19) NOT NULL, XID VARCHAR2(255) NULL, Y VARCHAR2(255) NULL, LEVEL VARCHAR2(255) NULL, STATE VARCHAR2(255) NULL, UDATE DATE NULL, PRIMARY KEY (ID))”)

Advertisement

Answer

Avtually Eclipse reported a bug that rises when there is a reserved word usage you can fine here :
https://bugs.eclipse.org/bugs/show_bug.cgi?id=260637.

the problem comes from using a reserved word I dont actually know your DBMS, if it is Mysql your attributs XID and LEVEL is a reserved word. you can find mysql reserved word here : https://dev.mysql.com/doc/refman/5.7/en/keywords.html.

You can also se from the sql code used to build your tables that there is a column name update of type DATE

UDATE DATE NULL

So to my opinion, you also need watch your attribut name on uDate

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement