我正在尝试使用EclipseLink作为jpa提供程序执行简单的JPA映射。
[![Persistence and Project Structure][1]][1]
上面的图片解释了项目结构和persistence.xml。 上面提到的数据库细节,我已经检查了oracle toad。我可以访问指定的模式,如下所示。
[![opening database connection ][2]][2]
在上图中,您可以看到连接。
following is the POJO
它是一个简单的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();
}
}
坚持pojo以上我写了下面的课
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();
}
}
执行后我得到以下错误 我不确定错误是因为它无法在META-INF文件夹中找到persistence.xml。它无法找到网址和驱动程序。
[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
如果需要更多信息,请告诉我。 谢谢
[1]: http://i.stack.imgur.com/PD0Ru.png
[2]: http://i.stack.imgur.com/iXEN0.png
答案 0 :(得分:0)
没有此类持久性属性javax.persistence.driver
等。
他们是
javax.persistence.jdbc.driver
javax.persistence.jdbc.user
等