Community
Participate
Working Groups
When eclipselink.jdbc.driver property is not set correctly I got the following NPE and this is a bit misleading. Exception in thread "main" java.lang.NullPointerException at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:436) at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:154) at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:91) at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:164) at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:578) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:214) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:234) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:69) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:118) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:112) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:100) Runtime should throw proper exception telling that there is no eclipselink.jdbc.driver property. Also JDBC-ODBC bridge driver is rarely used, so this is not definitely useful default.
Created attachment 93792 [details] patch Patch description: 1. Checking if JDBC URL property is set properly done. This will throw proper error message rather than NPE. 2. Modify DefaultConnector not to have default driver class name (JdbcOdbc). Even if driver class name is not given, DriverManager can use already loaded drivers for the URL. Also JDBC 4.0 drivers are loaded automatically(4.0 change) if they are in the classpath. Therefore eclipselink.jdbc.driver property can be optional.
Created attachment 93960 [details] patch2 Patch description: Considering sessions.xml and session customizer, this fix validates JDBC URL at connection creation time. Since Connector could be set with sessions.xml or could be overrided by session customizer, just checking eclipselink.jdbc.url is not always right.
Fix by Wonseok Kim Reviewed by Tom Ware Checked in Wonseok's fix. Thanks Wonseok. Tested with Full JPA and Full Core testing run. These changes are exercised each time persistence units are deployed on a Login is constructed, therefore no new tests have been added.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink