Wonseok Kim wrote:
> Hi Tom,
>
> I filed an issue for this.
>
https://bugs.eclipse.org/bugs/show_bug.cgi?id=224083
>
> Actually I was curious that at predeploy phase why DefaultConnector is
> always set to Login object and not used until it's replaced with real
> Connector(JNDIConnector or DefaultConnector with driver, url setting) at
> deploy time. I guess it's just dummy Connector which is not actually
> used at predeploy time.
>
> Anyway to address this issue I got two suggestions. One is checking JDBC
> URL property when setting this to Connector like below. This will throw
> proper error message rather than NPE.
>
> EntityManagerSetupImpl:
> protected void updateLoginDefaultConnector(DatasourceLogin login,
> Map m){
> String connectionString =
> getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_URL, m,
> session);
> if(connectionString == null)
> throw new
> javax.persistence.PersistenceException(EntityManagerSetupException.propertyIsMissing(PersistenceUnitProperties.JDBC_URL));
>
> String jdbcDriver =
> getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_DRIVER,
> m, session);
> // jdbcDriver is optional(could be null) because driver might be
> already loaded
>
> DefaultConnector connector = new DefaultConnector(jdbcDriver,
> "", connectionString);
> login.setConnector(connector);
> }
>
> Another one is modifying 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.
>
> For this DefaultConnector can to be modified like below.
>
> Index:
> /home/wons/works/eclipselink/foundation/eclipselink.core/src/org/eclipse/persistence/sessions/DefaultConnector.java
> ===================================================================
> ---
> /home/wons/works/eclipselink/foundation/eclipselink.core/src/org/eclipse/persistence/sessions/DefaultConnector.java
> (revision 13786)
> +++
> /home/wons/works/eclipselink/foundation/eclipselink.core/src/org/eclipse/persistence/sessions/DefaultConnector.java
> (working copy)
> @@ -47,11 +47,10 @@
>
> /**
> * PUBLIC:
> - * Construct a Connector with default settings (Sun JDBC-ODBC bridge).
> + * Construct a Connector with default settings.
> * The database URL will still need to be set.
> */
> public DefaultConnector() {
> - this("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:", "");
> }
>
> /**
> @@ -80,8 +79,8 @@
> * @return java.sql.Connection
> */
> public Connection connect(Properties properties, Session session)
> throws DatabaseException {
> - // ensure the driver has been loaded and registered
> - if(this.driverClass == null) {
> + // if driver class name is given, ensure the driver has been
> loaded and registered
> + if(this.driverClassName != null && this.driverClass == null) {
> this.loadDriverClass(session);
> }
>
> @@ -96,7 +95,12 @@
> }
> }
> }
> -
> +
> + if(this.driverClass == null) {
> + throw
> DatabaseException.sqlException(driverManagerException,
> (org.eclipse.persistence.internal.sessions.AbstractSession) session, true);
> + }
> +
> + // try driver class directly
> // Save secondary exception state and don't clear original
> exception
> boolean wrongDriverExceptionOccurred = false;
> try {
>
> I'll attach this fix to the issue soon.
>
> Cheers,
> -Wonseok
>
> On Wed, Mar 26, 2008 at 2:36 AM, Tom Ware <
tom.ware@xxxxxxxxxx