aspose file tools*
The moose likes Object Relational Mapping and the fly likes javax.persistence.PersistenceException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply locked New topic
Author

javax.persistence.PersistenceException

kunal green
Greenhorn

Joined: Dec 31, 2009
Posts: 26

Hi i am new to JPA,

m trying to make a simple jpa application.

My persistence.xml is as follows
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="JPATest">
<!--<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> -->
<class>com.jpatest.tables.EmpTable</class>
<properties>
<property name="eclipselink.jdbc.driver"
value="oracle.jdbc.driver.OracleDriver" />
<property name="eclipselink.jdbc.url"
value="jdbcracle:thin:@localhost:1521:XE" />
<property name="eclipselink.jdbc.user" value="kunal" />
<property name="eclipselink.jdbc.password" value="kunal" />
</properties>
</persistence-unit>
</persistence>


JPA class is
package com.jpatest.tables;

import java.io.Serializable;
import javax.persistence.*;
import javax.persistence.EntityManager;


/**
* The persistent class for the EMP_TABLE database table.
*
*/
@Entity
@Table(name="EMP_TABLE")
public class EmpTable implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name="EMP_ID")
private long empId;

@Column(name="EMP_ADDRESS")
private String empAddress;

@Column(name="EMP_NAME")
private String empName;

public EmpTable() {
}

public long getEmpId() {
return this.empId;
}

public void setEmpId(long empId) {
this.empId = empId;
}

public String getEmpAddress() {
return this.empAddress;
}

public void setEmpAddress(String empAddress) {
this.empAddress = empAddress;
}

public String getEmpName() {
return this.empName;
}

public void setEmpName(String empName) {
this.empName = empName;
}

}

and main class is

package com.jpatest.tables;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
public class Main {

/**
* @param args
*/

private static EntityManagerFactory factory;
private static final String PersistanceUnit ="EmpTable";

public static void main(String[] args) {
// TODO Auto-generated method stub


//getting entity managers instance
//creting entity manager factory instance for a particular table type
factory=Persistence.createEntityManagerFactory(PersistanceUnit);

//creting entity mangers instance
EntityManager em = factory.createEntityManager();
// Read the existing entries and write to console

//query to fetch all elements formt the table
Query q = em.createQuery("select t from Todo t");
List<EmpTable> todoList = q.getResultList();
for (EmpTable todo : todoList)
{
System.out.println("...............................");
System.out.println(todo);
System.out.println(todo.getEmpId());
System.out.println(todo.getEmpAddress());
System.out.println(todo.getEmpName());
System.out.println("...............................");
}
System.out.println("Size: " + todoList.size());

// Create new todo
em.getTransaction().begin();
EmpTable todo = new EmpTable();
todo.setEmpId(12);
todo.setEmpAddress("sec22");
todo.setEmpName("Mritunjar");
em.persist(todo);
em.getTransaction().commit();
em.close();


}

}


when i am executing this program i am getting error

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named EmpTable
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.jpatest.tables.Main.main(Main.java:23)
the location of persistence.xml is META-INF directory

Please help me out of this situation..
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Your persistence unit name is "JPATest" not "EmpTable"

<persistence-unit name="JPATest">

private static final String PersistanceUnit ="EmpTable";


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
kunal green
Greenhorn

Joined: Dec 31, 2009
Posts: 26

i did as you suggested and now resolved with the previous problem

thanks a lot for that

but unluckily i am stuck with the following exception now,please help

[EL Info]: 2011-05-09 21:56:47.634--ServerSession(23370564)--EclipseLink, version: Eclipse Persistence Services - 1.1.3.v20091002-r5404
[EL Severe]: 2011-05-09 21:56:47.653--ServerSession(23370564)--Local Exception Stack:
Exception [EclipseLink-4003] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [oracle.jdbc.driver.OracleDriver] not found.
at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:82)
at org.eclipse.persistence.sessions.DefaultConnector.loadDriverClass(DefaultConnector.java:265)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:84)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:583)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:227)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:112)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:164)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
at com.jpatest.tables.Main.main(Main.java:26)

Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [oracle.jdbc.driver.OracleDriver] not found.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:272)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:112)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:164)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
at com.jpatest.tables.Main.main(Main.java:26)
Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [oracle.jdbc.driver.OracleDriver] not found.
at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:82)
at org.eclipse.persistence.sessions.DefaultConnector.loadDriverClass(DefaultConnector.java:265)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:84)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:583)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:227)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
... 4 more
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
You need to add your JDBC driver jar to the classpath.
kunal green
Greenhorn

Joined: Dec 31, 2009
Posts: 26

I already have added odbc14.jar
somehow it is not getting detected what i feel

I added it to the classpath and then added to lib directory of web-inf both are not working.

please suggest solution
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
What environment are you using?
kunal green
Greenhorn

Joined: Dec 31, 2009
Posts: 26

I resolved the previous issue but again a new one cropped up
The console log is showing the following again it seems i am able to log in to the db but eclipselink somehow not able to create the query,may be a version related issue,need help


[EL Info]: 2011-05-11 22:09:57.068--ServerSession(10040532)--EclipseLink, version: Eclipse Persistence Services - 1.1.3.v20091002-r5404
[EL Info]: 2011-05-11 22:09:58.134--ServerSession(10040532)--file:/D:/ProjectsJava/JPATest/build/classes/-JPATest login successful
Exception in thread "main" java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1071)
at com.jpatest.tables.Main.main(Main.java:30)
Caused by: Exception [EclipseLink-8034] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Error compiling the query [select t from Todo t]. Unknown entity type [Todo].
at org.eclipse.persistence.exceptions.JPQLException.entityTypeNotFound(JPQLException.java:479)
at org.eclipse.persistence.internal.jpa.parsing.ParseTreeContext.classForSchemaName(ParseTreeContext.java:138)
at org.eclipse.persistence.internal.jpa.parsing.SelectNode.getClassOfFirstVariable(SelectNode.java:311)
at org.eclipse.persistence.internal.jpa.parsing.SelectNode.getReferenceClass(SelectNode.java:300)
at org.eclipse.persistence.internal.jpa.parsing.ParseTree.getReferenceClass(ParseTree.java:439)
at org.eclipse.persistence.internal.jpa.parsing.ParseTree.adjustReferenceClassForQuery(ParseTree.java:79)
at org.eclipse.persistence.internal.jpa.parsing.JPQLParseTree.populateReadQueryInternal(JPQLParseTree.java:103)
at org.eclipse.persistence.internal.jpa.parsing.JPQLParseTree.populateQuery(JPQLParseTree.java:84)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:160)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:134)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:91)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:78)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1069)
... 1 more






Environment descrption :
IDE: Eclipse Galelio
and its eclipse link jars(jar definition is in the exception trace)

dbracle 10g XE

Please help,
hopefully we are close to the successful execution of this prog...
kunal green
Greenhorn

Joined: Dec 31, 2009
Posts: 26

is any body there,please help me
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Looks like you've forgotten to map an entity called Todo.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
kunal green
Greenhorn

Joined: Dec 31, 2009
Posts: 26

I dnt have any entity calld todo.query z part of generated code by eclipselink
kunal green
Greenhorn

Joined: Dec 31, 2009
Posts: 26

is this some kind of eclipselink bug if yes then i wonder from where i can get the correct jars.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

No, not an eclipselink bug:

Like I said, you are querying for an entity called "Todo"



I already have added odbc14.jar

Not related, but are you running JDK 1.4? If not, get an up to date Driver.
kunal green
Greenhorn

Joined: Dec 31, 2009
Posts: 26

thanks a lot,now m getting my entiyies values in the output
Vimal Kumar Venugopal
Ranch Hand

Joined: Aug 20, 2011
Posts: 43

"Exception Description: Configuration error. Class [oracle.jdbc.driver.OracleDriver] not found"

"I resolved the previous issue" but again a new one cropped up


Hi Kunal,

It would be very helpful for me if you could describe how you resolved the issue.

Apologies for reopening this topic.

Regards,
Lamiv.


"Value has a Value only if its value is valued!"
pavan sanjay dixit
Greenhorn

Joined: Jul 26, 2012
Posts: 1
Vimal Kumar Venugopal wrote:"Exception Description: Configuration error. Class [oracle.jdbc.driver.OracleDriver] not found"

"I resolved the previous issue" but again a new one cropped up


Hi Kunal,

It would be very helpful for me if you could describe how you resolved the issue.

Apologies for reopening this topic.

Regards,
Lamiv.


hi,

i too was facing same error. you can check warnings in eclipse. there i right click and in option i have selected Quick fix option.
May be this will be useful to you.

Regards,
Pavan
kanagaraj palanisamy
Greenhorn

Joined: Mar 09, 2012
Posts: 1


follow this link: this works fine... http://www.vogella.com/articles/JavaPersistenceAPI/article.html#jpaintro_persistenceunits

also make sure that META-INF folder is in src folder of your project.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

This topic is already marked as resolved. New topics should be created for new questions. I am locking this thread to prevent it from getting resurrected again.


[How To Ask Questions][Read before you PM me]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.persistence.PersistenceException