jpa mysql table does not exists - java

I am trying to insert a Employee entity into the database. I am using JPA and the database is mysql.
When I try to insert the entity, it gives me test.employee does not exist. I assume that I dont have to create
the table. Entity will automatically create the table with the annotated name.
Please find the exception and code below.
Exception in thread "main" javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.employee' doesn't exist
Error Code: 1146
Call: INSERT INTO employee (FIRST_NAME, LAST_NAME) VALUES (?, ?)
bind => [abc,def]
Query: InsertObjectQuery(com.example.entities.Employee#ee1ede)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:157)
at com.example.dao.BaseDao.commitAndClose(BaseDao.java:41)
at com.example..dao.BaseDao.persist(BaseDao.java:29)
at com.example..dao.EmployeeDao.createEmployee(EmployeeDao.java:29)
at com.example.Main.main(KITMain.java:27)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.employee' doesn't exist
Error Code: 1146
Call: INSERT INTO employee (FIRST_NAME, LAST_NAME) VALUES (?, ?)
bind => [ram, mohan]
Query: InsertObjectQuerycom.example.entities.Employee#ee1ede)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:900)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:962)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:631)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1991)
at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:298)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:377)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:165)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:180)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:489)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:301)
at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:798)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1793)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1775)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1726)
at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:226)
at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:125)
at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:4196)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1441)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1531)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:277)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1169)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:132)
... 4 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.employee' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.Util.getInstance(Util.java:384)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4164)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2334)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2262)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2246)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:890)
persistence.xml
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<class>com.example.entities.Employee</class>
<properties>
<!-- derby -->
<!-- <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"
/> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"
/> <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/test"
/> <property name="javax.persistence.jdbc.user" value="app" /> <property
name="javax.persistence.jdbc.password" value="admin" /> -->
<!-- mysql -->
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
<!-- Configure simple SQL logging for demonstration. -->
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.thread" value="false" />
<property name="eclipselink.logging.session" value="false" />
<property name="eclipselink.logging.exceptions" value="false" />
<property name="eclipselink.logging.timestamp" value="false" />
</properties>
</persistence-unit>
package com.example.entities;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
*
* #author ddd
*/
#Entity
#Table(name = "employee")
public class Employee implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "EMP_ID")
private String employeeId;
#Column(name = "FIRST_NAME")
private String firstName;
#Column(name = "LAST_NAME")
private String lastName ;
public String getEmployeeId() {
return employeeId;
}
public void setEmployeeId(String employeeId) {
this.employeeId = employeeId;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
[EL Config]: metadata: The access type for the persistent class [class de.allianz.kit.server.persistence.entities.Employee] is set to [FIELD].
[EL Config]: metadata: The alias name for the entity class [class de.allianz.kit.server.persistence.entities.Employee] is being defaulted to: Employee.
[EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5
[EL Fine]: connection: Detected database platform: org.eclipse.persistence.platform.database.MySQLPlatform
[EL Config]: connection: Connection(3278348)--connecting(DatabaseLogin(
platform=>MySQLPlatform
user name=> "root"
datasource URL=> "jdbc:mysql://localhost:3306/test"
))
[EL Config]: connection: Connection(5863106)--Connected: jdbc:mysql://localhost:3306/test
User: root#localhost
Database: MySQL Version: 5.6.17
Driver: MySQL Connector Java Version: mysql-connector-java-5.1.30 ( Revision: alexander.soklakov#oracle.com-20140310090514-8xt1yoht5ksg2e7c )
[EL Info]: connection: file:/C:/myworkspace/kit_ws/com.example.server.persistence/classes/_kit login successful
[EL Fine]: sql: Connection(5863106)--DROP TABLE employee
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'test.employee'
Error Code: 1051
Call: DROP TABLE employee
Query: DataModifyQuery(sql="DROP TABLE employee")
[EL Fine]: sql: Connection(5863106)--DROP TABLE employee
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'test.employee'
Error Code: 1051
Call: DROP TABLE employee
Query: DataModifyQuery(sql="DROP TABLE employee")
[EL Fine]: sql: Connection(5863106)--DROP TABLE employee
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'test.employee'
Error Code: 1051
Call: DROP TABLE employee
Query: DataModifyQuery(sql="DROP TABLE employee")
[EL Fine]: sql: Connection(5863106)--DROP TABLE employee
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'test.employee'
Error Code: 1051
Call: DROP TABLE employee
Query: DataModifyQuery(sql="DROP TABLE employee")
[EL Fine]: sql: Connection(5863106)--DROP TABLE employee
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'test.employee'
Error Code: 1051
Call: DROP TABLE employee
Query: DataModifyQuery(sql="DROP TABLE employee")
[EL Fine]: sql: Connection(5863106)--CREATE TABLE employee (EMP_ID VARCHAR(255) AUTO_INCREMENT NOT NULL, FIRST_NAME VARCHAR(255), LAST_NAME VARCHAR(255), PRIMARY KEY (EMP_ID))
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Incorrect column specifier for column 'EMP_ID'
Error Code: 1063
Call: CREATE TABLE employee (EMP_ID VARCHAR(255) AUTO_INCREMENT NOT NULL, FIRST_NAME VARCHAR(255), LAST_NAME VARCHAR(255), PRIMARY KEY (EMP_ID))
Query: DataModifyQuery(sql="CREATE TABLE employee (EMP_ID VARCHAR(255) AUTO_INCREMENT NOT NULL, FIRST_NAME VARCHAR(255), LAST_NAME VARCHAR(255), PRIMARY KEY (EMP_ID))")
[EL Fine]: sql: Connection(5863106)--INSERT INTO employee (FIRST_NAME, LAST_NAME) VALUES (?, ?)
bind => [ram, mohan]
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.employee' doesn't exist
Error Code: 1146

You will need extra configuration if you want an auto generated varchar.
The generation of DDL is translating to:
CREATE TABLE employee (EMP_ID VARCHAR(255) AUTO_INCREMENT NOT NULL, FIRST_NAME VARCHAR(255), LAST_NAME VARCHAR(255), PRIMARY KEY (EMP_ID))
and the log is saying:
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Incorrect column specifier for column 'EMP_ID'
Error Code: 1063
MySql is rejecting EMP_ID becuase it cant have AUTO_INCREMENT with varchar, and you need to specify the auto generation for it. Probably Derby has this feature, and it works different for MySql.
You might wanna look in this answer.
Or just change the type of EMP_ID to an integer number if you dont mind the type or for a quick test.

Could be you mysql data is corrupted.
Go to Mysql home directory and delete all .frm extension. and restart Msysql server.
Solved.

Related

The persistence doesn't recognize the entity class

I am developing a java program about some lotteries of my country, it has a database with the lottos and other numbers. There is no problem with the entity classes, but when I run the problem my persistence unit does not recognize one entity class. I am a beginner in java, thanks in advance.
Here is the Numbers entity class:
#Entity
#Table(name = "NUMBERS")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Numbers.findAll", query = "SELECT n FROM Numbers n")
, #NamedQuery(name = "Numbers.findById", query = "SELECT n FROM Numbers n WHERE n.id = :id")
, #NamedQuery(name = "Numbers.findByNum", query = "SELECT n FROM Numbers n WHERE n.num = :num AND n.lotto = :lotto")
, #NamedQuery(name = "Numbers.findByAssociated", query = "SELECT n FROM Numbers n WHERE n.num = :num AND n.associated = :associated AND n.lotto = :lotto")
, #NamedQuery(name = "Numbers.findByLotto", query = "SELECT n FROM Numbers n WHERE n.lotto = :lotto")})
public class Numbers implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "ID")
private Integer id;
#Basic(optional = false)
#Column(name = "NUM")
private int num;
#Basic(optional = false)
#Column(name = "ASSOCIATED")
private int associated;
#Basic(optional = false)
#Column(name = "LOTTO")
private String lotto;
And the code that I use to insert Numbers in the database:
public static boolean insertAlert(EntityManager em, Numbers an) {
boolean success = false;
Alert alert = Check.createAlert(Check.CONFIRMATION, "Añadir números asociados", "¿Deseas añadir estos números?");
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) {
em.getTransaction().begin();
em.persist(an);
if (em.isJoinedToTransaction()) {
em.getTransaction().commit();
System.out.println("NUMBERS SUCCESSFULLY ADDED!");
alert = Check.createAlert(Check.INFORMATION, "OK", "Números añadidos!");
alert.showAndWait();
success = true;
}
em.clear();
}
return success;
}
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="LotterPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>lotter.lottoClasses.Gordo</class>
<class>lotter.lottoClasses.Primitiva</class>
<class>lotter.lottoClasses.Eurojackpot</class>
<class>lotter.lottoClasses.Seis49</class>
<class>lotter.lottoClasses.Superonce</class>
<class>lotter.lottoClasses.Bonoloto</class>
<class>lotter.lottoClasses.Siete39</class>
<class>lotter.lottoClasses.Euromillones</class>
<class>lotter.Repetition</class>
<class>lotter.Numbers</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:DB;create=true"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
The persistence unit recognizes all my entity classes but not this one, I don't know how to resolve this...
Caused by: java.lang.IllegalArgumentException: Object: lotter.Numbers[ id=null ] is not a known entity type.
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4228)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:496)
at lotter.Numbers.insertAlert(Numbers.java:165)
at lotter.Numbers.insertAssociated(Numbers.java:150)
at lotter.Lotter.start(Lotter.java:41)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application lotter.Lotter
JPA Logging:
[EL Finer]: metadata: 2019-10-17 16:14:45.632--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--Searching for default mapping file in file:/Users/~/NetBeansProjects/Lotter/build/classes/ (There is no English translation for this message.)
[EL Finer]: metadata: 2019-10-17 16:14:45.643--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--Searching for default mapping file in file:/Users/~/NetBeansProjects/Lotter/build/classes/ (There is no English translation for this message.)
[EL Config]: metadata: 2019-10-17 16:14:45.803--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Bonoloto] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.825--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Euromillones] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.827--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.Repetition] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.832--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Gordo] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.833--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Seis49] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.834--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Primitiva] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.835--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Siete39] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.835--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Superonce] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.836--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The access type for the persistent class [class lotter.lottoClasses.Eurojackpot] is set to [FIELD].
[EL Config]: metadata: 2019-10-17 16:14:45.837--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Bonoloto] is being defaulted to: Bonoloto.
[EL Config]: metadata: 2019-10-17 16:14:45.868--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Euromillones] is being defaulted to: Euromillones.
[EL Config]: metadata: 2019-10-17 16:14:45.869--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.Repetition] is being defaulted to: Repetition.
[EL Config]: metadata: 2019-10-17 16:14:45.87--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Gordo] is being defaulted to: Gordo.
[EL Config]: metadata: 2019-10-17 16:14:45.871--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Seis49] is being defaulted to: Seis49.
[EL Config]: metadata: 2019-10-17 16:14:45.873--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Primitiva] is being defaulted to: Primitiva.
[EL Config]: metadata: 2019-10-17 16:14:45.874--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Siete39] is being defaulted to: Siete39.
[EL Config]: metadata: 2019-10-17 16:14:45.875--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Superonce] is being defaulted to: Superonce.
[EL Config]: metadata: 2019-10-17 16:14:45.878--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--The alias name for the entity class [class lotter.lottoClasses.Eurojackpot] is being defaulted to: Eurojackpot.
[EL Finest]: jpa: 2019-10-17 16:14:46.059--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--End predeploying Persistence Unit LotterPU; session file:/Users/user/NetBeansProjects/Lotter/build/classes/_LotterPU; state Predeployed; factoryCount 0
[EL Finer]: weaver: 2019-10-17 16:14:46.059--Thread(Thread[JavaFX Application Thread,5,main])--JavaSECMPInitializer - transformer is null.
[EL Finest]: jpa: 2019-10-17 16:14:46.059--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--Begin predeploying Persistence Unit LotterPU; session file:/Users/user/NetBeansProjects/Lotter/build/classes/_LotterPU; state Predeployed; factoryCount 0
[EL Finest]: jpa: 2019-10-17 16:14:46.059--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--End predeploying Persistence Unit LotterPU; session file:/Users/user/NetBeansProjects/Lotter/build/classes/_LotterPU; state Predeployed; factoryCount 1
[EL Finest]: jpa: 2019-10-17 16:14:46.065--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--Begin deploying Persistence Unit LotterPU; session file:/Users/user/NetBeansProjects/Lotter/build/classes/_LotterPU; state Predeployed; factoryCount 1
[EL Finer]: 2019-10-17 16:14:46.088--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--Could not initialize Validation Factory. Encountered following exception: java.lang.NoClassDefFoundError: javax/validation/Validation
[EL Finest]: properties: 2019-10-17 16:14:46.092--ServerSession(1410760993)--Thread(Thread[JavaFX Application Thread,5,main])--property=eclipselink.logging.logger; value=org.eclipse.persistence.logging.DefaultSessionLog
I had the same problem and none of the answers here fixed it.
My solution was to updated my EclipseLink version from 2.5.1 to the latest version 2.7.7 as described in this other post.
Persist only takes on entity not a list of.
So you have to iterate over the array and persist each Numbers object separately.
for (Numbers n : ans) {
em.persist(ans);
}
Common reasons for this error:
An older persistence.xml file is on the class path that doesn't
have your lotter.Numbers entry.
The class loader used to obtain the EntityManager isn't the same one
that loaded the 'an' Answer instance you are passing to the
em.persist call.
The first issue is far more common, and can be found more easily by enabling EclipseLink logging and then checking the log when it deploys the persistence unit to see what classes and mappings are loaded. Variations of it are just deploying the wrong jar, having an older jar on the class path first etc.
EclipseLink uses the class to lookup the metadata in a hash map, so if different class loaders are used, it won't find anything for it. This is a less common issue that depends on how you are loading your EntityManagerFactory and the container classloader structure. You would have problems with more then just one of your JPA entities, but it would depend on where they are coming from too.

jpa mysql table does not exists autoGenerate doesn't work

i am trying to insert a Employee entity into the database. I am using JPA and the database is mysql. When I try to insert the entity, it gives me tables must be created I assume that I dont have to create the table. Entity will automatically create the table with the annotated name. Please find the exception and code below.
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'gsq.articles' doesn't exist
Error Code: 1146
Call: CREATE TABLE articles (id INTEGER AUTO_INCREMENT NOT NULL, libelle VARCHAR(255), ENTREPRISE_id INTEGER, PRIMARY KEY (id))
Query: DataModifyQuery(sql="CREATE TABLE articles (id INTEGER AUTO_INCREMENT NOT NULL, libelle VARCHAR(255), ENTREPRISE_id INTEGER, PRIMARY KEY (id))")
[EL Fine]: 2017-11-12 20:57:29.914--ServerSession(162116790)--Connection(578752466)--CREATE TABLE entreprise (id INTEGER AUTO_INCREMENT NOT NULL, libelle VARCHAR(255) UNIQUE, PRIMARY KEY (id))
[EL Fine]: 2017-11-12 20:57:29.919--ServerSession(162116790)--SELECT 1
[EL Warning]: 2017-11-12 20:57:29.921--ServerSession(162116790)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'gsq.entreprise' doesn't exist
Error Code: 1146
Call: CREATE TABLE entreprise (id INTEGER AUTO_INCREMENT NOT NULL, libelle VARCHAR(255) UNIQUE, PRIMARY KEY (id))
Query: DataModifyQuery(sql="CREATE TABLE entreprise (id INTEGER AUTO_INCREMENT NOT NULL, libelle VARCHAR(255) UNIQUE, PRIMARY KEY (id))")
[EL Fine]: 2017-11-12 20:57:29.922--ServerSession(162116790)--Connection(578752466)--CREATE TABLE users (ID BIGINT AUTO_INCREMENT NOT NULL, password VARCHAR(255), type VARCHAR(255), username VARCHAR(255) UNIQUE, PRIMARY KEY (ID))
[EL Fine]: 2017-11-12 20:57:29.927--ServerSession(162116790)--SELECT 1
[EL Warning]: 2017-11-12 20:57:29.929--ServerSession(162116790)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'gsq.users' doesn't exist
Error Code: 1146
Call: CREATE TABLE users (ID BIGINT AUTO_INCREMENT NOT NULL, password VARCHAR(255), type VARCHAR(255), username VARCHAR(255) UNIQUE, PRIMARY KEY (ID))
Query: DataModifyQuery(sql="CREATE TABLE users (ID BIGINT AUTO_INCREMENT NOT NULL, password VARCHAR(255), type VARCHAR(255), username VARCHAR(255) UNIQUE, PRIMARY KEY (ID))")
[EL Fine]: 2017-11-12 20:57:29.93--ServerSession(162116790)--Connection(578752466)--ALTER TABLE articles ADD CONSTRAINT FK_articles_ENTREPRISE_id FOREIGN KEY (ENTREPRISE_id) REFERENCES entreprise (id)
[EL Fine]: 2017-11-12 20:57:29.935--ServerSession(162116790)--SELECT 1
[EL Warning]: 2017-11-12 20:57:29.936--ServerSession(162116790)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'gsq.articles' doesn't exist
Error Code: 1146
Call: ALTER TABLE articles ADD CONSTRAINT FK_articles_ENTREPRISE_id FOREIGN KEY (ENTREPRISE_id) REFERENCES entreprise (id)
Query: DataModifyQuery(sql="ALTER TABLE articles ADD CONSTRAINT FK_articles_ENTREPRISE_id FOREIGN KEY (ENTREPRISE_id) REFERENCES entreprise (id)")
[EL Fine]: 2017-11-12 20:57:30.035--ServerSession(162116790)--Connection(578752466)--SELECT id, libelle FROM entreprise
[EL Fine]: 2017-11-12 20:57:30.035--ServerSession(162116790)--SELECT 1
[EL Warning]: 2017-11-12 20:57:30.035--UnitOfWork(1734860123)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'gsq.entreprise' doesn't exist
Error Code: 1146
Call: SELECT id, libelle FROM entreprise
Query: ReadAllQuery(referenceClass=Entreprise sql="SELECT id, libelle FROM entreprise")
Exception in thread "AWT-EventQueue-0" javax.persistence.RollbackException: Transaction rolled back because transaction was set to RollbackOnly.
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:92)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
at controlleur.Executerequest.closeEntityManager(Executerequest.java:73)
at frame.ArticlesFram.MajComBox(ArticlesFram.java:385)
at frame.ArticlesFram.<init>(ArticlesFram.java:53)
at frame.ArticlesFram$13.run(ArticlesFram.java:501)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="GSQPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>entities.Articles</class>
<class>entities.Entreprise</class>
<class>entities.Users</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/gsq"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
Artcile entity
#Entity
#Table(name = "articles")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Articles.findAll", query = "SELECT a FROM Articles a"),
#NamedQuery(name = "Articles.findById", query = "SELECT a FROM Articles a WHERE a.id = :id"),
#NamedQuery(name = "Articles.findByLibelle", query = "SELECT a FROM Articles a WHERE a.libelle = :libelle")})
public class Articles implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "id")
private Integer id;
#Column(name = "libelle")
private String libelle;
#ManyToOne
private Entreprise entreprise;
public Articles() {
}
public Articles(Integer id) {
this.id = id;
}
}
I haven't work with eclipselink, but checking a few example and can see that all have mentioned below 4 properties each time:
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.create-ddl-jdbc-file-name" value="createDDL_ddlGeneration.jdbc"/>
<property name="eclipselink.drop-ddl-jdbc-file-name" value="dropDDL_ddlGeneration.jdbc"/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
might be the cause ?
the problem was at the database level and not with jpa I solved it by connecting to another database thx

JPA 2.1 derby/javadb create script with line breaks will not run

Please have a look on my create script.
My goal is to controll the creation of the schema by script and let the dropping be handled by the metadata stuff.
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.target-database" value="DERBY" />
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver" />
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
<property name="javax.persistence.schema-generation.script.action" value="create" />
<property name="javax.persistence.schema-generation.create-source" value="script" />
<property name="javax.persistence.schema-generation.create-script-source"
value="file:/home/kevin/workspace_pluginDev/zvagent/src/main/resources/META-INF/sql/create_tables.ddl" />
<property name="javax.persistence.sql-load-script-source"
value="file:/home/kevin/workspace_pluginDev/zvagent/src/main/resources/META-INF/sql/load_stammdaten.sql" />
The create script will be executed but fails on the end of the first line. It seems like the create script is executed line wise and not statement by statement:
The create script
I tested this script successfully on the same DB connection inside Eclipse using a SQL-Scrapbook editor.
CREATE TABLE TABELLENNAME (
"BESCHREIBUNG" VARCHAR(255),
"ID" BIGINT NOT NULL PRIMARY KEY,
"LASTUPDATE" BIGINT,
"SONSTIGES" VARCHAR(255),
);
But when called from JPA this happens:
Log/Error messages from the DB
[EL Fine]: sql: 2014-03-09 13:45:44.167--ServerSession(194685468)--Connection(1337157493)--Thread(Thread[main,5,main])--CREATE TABLE TABELLENNAME (
[EL Fine]: sql: 2014-03-09 13:45:44.17--ServerSession(194685468)--Thread(Thread[main,5,main])--VALUES(1)
[EL Warning]: 2014-03-09 13:45:44.172--ServerSession(194685468)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Syntaxfehler: Encountered "<EOF>" at line 1, column 27.
Error Code: 0
Call: CREATE TABLE TABELLENNAME (
Query: DataModifyQuery(sql="CREATE TABLE TABELLENNAME (")
[EL Fine]: sql: 2014-03-09 13:45:44.172--ServerSession(194685468)--Connection(1337157493)--Thread(Thread[main,5,main])--"BESCHREIBUNG" VARCHAR(255),
[EL Fine]: sql: 2014-03-09 13:45:44.179--ServerSession(194685468)--Thread(Thread[main,5,main])--VALUES(1)
[EL Warning]: 2014-03-09 13:45:44.181--ServerSession(194685468)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Syntaxfehler: Encountered "\"BESCHREIBUNG\"" at line 1, column 1.
Error Code: 0
Call: "BESCHREIBUNG" VARCHAR(255),
Query: DataModifyQuery(sql=""BESCHREIBUNG" VARCHAR(255),")
[EL Fine]: sql: 2014-03-09 13:45:44.182--ServerSession(194685468)--Connection(1337157493)--Thread(Thread[main,5,main])--"ID" BIGINT NOT NULL PRIMARY KEY,
[EL Fine]: sql: 2014-03-09 13:45:44.184--ServerSession(194685468)--Thread(Thread[main,5,main])--VALUES(1)
[EL Warning]: 2014-03-09 13:45:44.186--ServerSession(194685468)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Syntaxfehler: Encountered "\"ID\"" at line 1, column 1.
Error Code: 0
Call: "ID" BIGINT NOT NULL PRIMARY KEY,
Query: DataModifyQuery(sql=""ID" BIGINT NOT NULL PRIMARY KEY,")
[EL Fine]: sql: 2014-03-09 13:45:44.193--ServerSession(194685468)--Connection(1337157493)--Thread(Thread[main,5,main])--"LASTUPDATE" BIGINT,
[EL Fine]: sql: 2014-03-09 13:45:44.196--ServerSession(194685468)--Thread(Thread[main,5,main])--VALUES(1)
[EL Warning]: 2014-03-09 13:45:44.198--ServerSession(194685468)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Syntaxfehler: Encountered "\"LASTUPDATE\"" at line 1, column 1.
Error Code: 0
Call: "LASTUPDATE" BIGINT,
Query: DataModifyQuery(sql=""LASTUPDATE" BIGINT,")
[EL Fine]: sql: 2014-03-09 13:45:44.198--ServerSession(194685468)--Connection(1337157493)--Thread(Thread[main,5,main])--"SONSTIGES" VARCHAR(255),
[EL Fine]: sql: 2014-03-09 13:45:44.202--ServerSession(194685468)--Thread(Thread[main,5,main])--VALUES(1)
[EL Warning]: 2014-03-09 13:45:44.203--ServerSession(194685468)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Syntaxfehler: Encountered "\"SONSTIGES\"" at line 1, column 1.
Error Code: 0
Call: "SONSTIGES" VARCHAR(255),
Query: DataModifyQuery(sql=""SONSTIGES" VARCHAR(255),")
[EL Fine]: sql: 2014-03-09 13:45:44.204--ServerSession(194685468)--Connection(1337157493)--Thread(Thread[main,5,main])--);
[EL Fine]: sql: 2014-03-09 13:45:44.206--ServerSession(194685468)--Thread(Thread[main,5,main])--VALUES(1)
[EL Warning]: 2014-03-09 13:45:44.208--ServerSession(194685468)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Syntaxfehler: Encountered ")" at line 1, column 1.
Error Code: 0
Call: );
Query: DataModifyQuery(sql=");")
Q: Is there a way to format the create scripts human readable but at the same time executable as create script?

Intellij 13 EclipseLink Class [] not found Error

i ve a huge problem with intellij 13.0.1. I set up a JPA Project for the first time in intellij 13 and need some help to get some rid of an strange error.
Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [] not found.
I added a persistence Unit and add the datasource, if i test the connection it is successfull. I also added eclipselink in version 2.5.1 and postgres.jdbc.driver in 9.3-1100. I also installed Postgres # latest build. I get the error if i want to create an Entitymanager. Any idea what i could do to get rid of this error?
src:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("RoomDB");
EntityManager em = emf.createEntityManager(); //<- Configuration Error
em.getTransaction().begin();
User user1 = new User();
user1.setUsername("testuser");
user1.setPassword("testuser");
em.persist(user1);
Room room1 = new Room();
room1.setRoom_nr(12);
em.persist(room1);
em.getTransaction().commit();
em.close();
Stack-Trace:
[EL Info]: transaction: 2013-12-30 23:16:13.05--ServerSession(20030435)--property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.062--ServerSession(20030435)--property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.062--ServerSession(20030435)--property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.062--ServerSession(20030435)--property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.949--ServerSession(20030435)--property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.949--ServerSession(20030435)--property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.95--ServerSession(20030435)--property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.95--ServerSession(20030435)--property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead.
[EL Info]: 2013-12-30 23:16:15.632--ServerSession(20030435)--EclipseLink, version: Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5
[EL Severe]: ejb: 2013-12-30 23:16:15.639--ServerSession(20030435)--Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [] not found.
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [] not found.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:766)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:182)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getDatabaseSession(EntityManagerFactoryImpl.java:527)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:140)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at de.Enviroment.main(Enviroment.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [] not found.
at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:89)
at org.eclipse.persistence.sessions.DefaultConnector.loadDriverClass(DefaultConnector.java:267)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:85)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:204)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:741)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
... 13 more
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="RoomDB">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>de.Entity.Room</class>
<class>de.Entity.User</class>
<properties>
<property name="eclipselink.jdbc.url" value=""/>
<property name="eclipselink.jdbc.driver" value=""/>
<property name="eclipselink.jdbc.user" value=""/>
<property name="eclipselink.jdbc.password" value=""/>
</properties>
</persistence-unit>
</persistence>
<property name="eclipselink.jdbc.driver" value=""/>
I'd say that's your problem. You're explicitly specifying no driver. Omit it or use org.postgresql.Driver.

Error while binding a table from postgresql Database to Netbeans GUI table

After binding a table from postgresql to a table in the design form in Netbeans, I got the following error:
run:
[EL Info]: 2013-10-04 10:51:36.097--ServerSession(865393238)--EclipseLink, version: Eclipse Persistence Services - 2.5.0.v20130507-3faac2b
[EL Info]: connection: 2013-10-04 10:51:36.701--ServerSession(865393238)--file:/D:/Doodle Notes Database/Doodle Notes Projects/build/classes/_DoodleNotesPU login successful
[EL Warning]: 2013-10-04 10:51:37.119--UnitOfWork(1785038318)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "doodlenotes.public.projects"
Position: 139
Error Code: 0
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "doodlenotes.public.projects"
Call: SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects
Position: 139
Error Code: 0
Query: ReadAllQuery(referenceClass=Projects sql="SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects")
Call: SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects
Query: ReadAllQuery(referenceClass=Projects sql="SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects")
at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:377)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:468)
at Doodle.doodleNotes_Business.initComponents(doodleNotes_Business.java:26)
at Doodle.doodleNotes_Business.<init>(doodleNotes_Business.java:11)
at Doodle.doodleNotes_Business.main(doodleNotes_Business.java:311)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "doodlenotes.public.projects"
Position: 139
Error Code: 0
Call: SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects
Query: ReadAllQuery(referenceClass=Projects sql="SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:679)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1995)
at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2714)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2667)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:477)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1155)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1114)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:402)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1202)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2894)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1797)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1779)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1744)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
... 4 more
Caused by: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "doodlenotes.public.projects"
Position: 139
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1002)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:641)
... 24 more
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)
What should I do to fix the error?
I have same error with IntelliJ IDEA and Hybernate,
Caused by: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "mydb.public.media_types"
Same as yours,
Caused by: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "doodlenotes.public.projects"
I have found solution, for my trouble, and I suppose for your's too, my solution is just to remove attribute named, catalog from my hbm.xml file.
before:
`<class name="pkg.MediaTypesEntity" table="media_types" schema="public"` catalog="MyDB">
after:
<!-- catalog="MyDB" --removed -->
<class name="pkg.MediaTypesEntity" table="media_types" schema="public">
<!-- catalog="MyDB" --removed -->
<id name="id">
<column name="id" sql-type="serial" not-null="true"/>
</id>
<property name="txt">
<column name="txt" sql-type="text" length="2147483647"/>
</property>
</class>
I suppose reason is that database name was configured globally at hibernate.cfg.xml .
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:postgresql://localhost:5432/MyDB</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<mapping resource="pkg/MediaTypesEntity.hbm.xml"/>
<mapping class="pkg.MediaTypesEntity"/>
</session-factory>
</hibernate-configuration>
And, real reason, MyDB name can not be easily removed from JDBC connection string. Only several different hibernate-DBName.cfg.xml allowed.
See, these links, for details:
hibernate-using-two-different-database-schemas-in-the-same-application
how-to-connect-to-multiple-databases-in-hibernate

Categories