Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA connection using eclipselink for oracle

Ashish ParabJun 14 2016 — edited Jun 14 2016

I am trying to execute simple JPA mapping using EclipseLink as jpa provider.

persistence.png

above image explains the project structure and persistence.xml.

above mentioned database details, i have checked in oracle toad. I am able to access specified schema as shown below.

toad.png

in above image, you could see the connection.

following is the POJO

package com.sun.arise;

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.GenerationType;

import javax.persistence.Id;

import javax.persistence.Table;

@Entity

@Table(name="Sun")

public class Sun {

@Id

@GeneratedValue(strategy=GenerationType.AUTO)

private int sunid;

@Column(name="DAY")

private String day;

@Column(name="MONTH")

private String month;

public String getDay() {

return day;

}

public void setDay(String day) {

this.day = day;

}

public String getMonth() {

return month;

}

public void setMonth(String month) {

this.month = month;

}

public int getSunId()

{

return sunid;

}

@Override

public String toString()

{

return getSunId()+"\n"+getDay()+"\n"+getMonth();

}

}

to persist above pojo i wrote following class

package com.sun.sunset;

import javax.persistence.EntityManager;

import javax.persistence.EntityManagerFactory;

import javax.persistence.Persistence;

import com.sun.arise.Sun;

public class TestSun {

public static void main(String args[])

{

String persistenceUnitName="myAttemptAtJPA";

EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName);

EntityManager em = emf.createEntityManager();

Sun z = new Sun();

z.setDay("Saturday");

z.setMonth("January");

em.getTransaction().begin();

em.persist(z);

em.getTransaction().commit();

}

}

after executing i am getting following errors

[EL Fine]: server: 2016-06-14 17:02:31.478--Thread(Thread[main,5,main])--Configured server platform: org.eclipse.persistence.platform.server.NoServerPlatform

[EL Config]: metadata: 2016-06-14 17:02:31.592--ServerSession(19166103)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.sun.arise.Sun] is set to [FIELD].

[EL Config]: metadata: 2016-06-14 17:02:31.612--ServerSession(19166103)--Thread(Thread[main,5,main])--The alias name for the entity class [class com.sun.arise.Sun] is being defaulted to: Sun.

[EL Config]: metadata: 2016-06-14 17:02:31.627--ServerSession(19166103)--Thread(Thread[main,5,main])--The column name for element [sunid] is being defaulted to: SUNID.

[EL Info]: 2016-06-14 17:02:31.65--ServerSession(19166103)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.6.3.v20160428-59c81c5

[EL Severe]: ejb: 2016-06-14 17:02:31.652--ServerSession(19166103)--Thread(Thread[main,5,main])--Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.6.3.v20160428-59c81c5): org.eclipse.persistence.exceptions.DatabaseException

Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform

Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.6.3.v20160428-59c81c5): org.eclipse.persistence.exceptions.DatabaseException

Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform

at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:815)

at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205)

at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:305)

at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:337)

at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:303)

at com.sun.sunset.TestSun.main(TestSun.java:15)

Caused by: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.6.3.v20160428-59c81c5): org.eclipse.persistence.exceptions.DatabaseException

Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform

at org.eclipse.persistence.exceptions.DatabaseException.unableToAcquireConnectionFromDriverException(DatabaseException.java:383)

at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:91)

at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)

at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:207)

at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:760)

at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:265)

at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:731)

... 5 more

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2016
Added on Jun 14 2016
1 comment
2,585 views