2016-06-14 82 views
-1

我想使用EclipseLink作爲jpa提供程序執行簡單的JPA映射。JPA連接eclipselink作爲提供程序和oracle作爲數據庫

[![Persistence and Project Structure][1]][1] 

上面的圖解釋了項目結構和persistence.xml。 上面提到的數據庫細節,我已經檢查了甲骨文蟾蜍。我能夠訪問如下所示的指定模式。

[![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(); 

} 
} 

執行我收到以下錯誤後 我不知道錯誤是因爲它是無法找到的persistence.xml的META-INF夾。它無法找到網址和驅動程序。

[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

有沒有這樣的持久性javax.persistence.driver

他們

javax.persistence.jdbc.driver 
javax.persistence.jdbc.user