2013-05-06 56 views
1

我想在運行時創建的EntityManager,所以我可以從config.xml中錯誤EclipseLink-4021在運行時創建EntityManager時爲什麼?

這裏設置不同的用戶名和密碼是創造了EntityManager

map.put(PersistenceUnitProperties.JDBC_USER, SystemConfig.getConfig().getString("jdbcUser")); 
map.put(PersistenceUnitProperties.JDBC_PASSWORD, SystemConfig.getConfig().getString("jdbcPassword")); 
map.put(PersistenceUnitProperties.JDBC_URL, SystemConfig.getConfig().getString("jdbcUrl")); 
map.put(PersistenceUnitProperties.JDBC_DRIVER, "net.sourceforge.jtds.jdbc.Driver"); 
EntityManager eMgr = Persistence.createEntityManagerFactory("myPU", map).createEntityManager(); 

在UNIX我的程序結構的代碼: 〜/測試/ myProgram.jar 〜/測試/ lib目錄/ *。JAR但是(所有圖書館和了jdbc.jar這裏)

當我運行該文件夾/測試程序裏面的程序工作正常/ 當我在根目錄下運行程序〜/我得到Ex ception [EclipseLink-4021]。 任何想法爲什麼?

注意:最終我需要使用cron作業來安排程序。

[EL Info]: 2013-05-06 12:10:18.989--ServerSession(1729331687)--EclipseLink, version: Eclipse Persistence Services - 2.4.1.v20121003-ad44345 
[EL Severe]: ejb: 2013-05-06 12:10:19.002--ServerSession(1729331687)--Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException 
Exception Description: Unable to acquire a connection from driver [net.sourceforge.jtds.jdbc.Driver], 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.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException 
Exception Description: Unable to acquire a connection from driver [net.sourceforge.jtds.jdbc.Driver], 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:602) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:186) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:278) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:304) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:282) 
     at dcsmailcheck.MailResend.<init>(MailResend.java:61) 
     at dcsmailcheck.Main.main(Main.java:49) 
Caused by: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException 
Exception Description: Unable to acquire a connection from driver [net.sourceforge.jtds.jdbc.Driver], 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:376) 
     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.loginAndDetectDatasource(DatabaseSessionImpl.java:685) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:215) 
     at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:542) 
     ... 6 more 

回答

0

由於您的代碼在〜/ test文件夾中工作,似乎SystemConfig.getConfig()無法加載該位置的屬性。確保已將您的屬性的路徑添加到CLASSPATH。

+0

是的,謝謝。它混淆了我在其他情況下,如果SystemConfig.getConfig()有問題,它會給出一個錯誤,「jdbcUser」或任何不可訪問或不存在等,但在上述情況下使用時,它不會提示該錯誤,而是提示EclipseLink錯誤... – codeIsFun 2013-05-08 01:20:01

相關問題