From 65d2ea8b1922cae9f68dddbdcd1e8e1212a62ba4 Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Thu, 15 Oct 2009 23:32:44 +0000 Subject: [PATCH] OPENJPA-1351: fix ClassCastException when downlevel jdbc driver is used. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@825699 13f79535-47bb-0310-9956-ffa450edef68 --- .../jdbc/conf/JDBCConfigurationImpl.java | 18 ++++++++++++++++-- .../openjpa/jdbc/conf/localizer.properties | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java index f2b369e4a..fa9efd33c 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java @@ -760,8 +760,22 @@ public class JDBCConfigurationImpl public Object getConnectionFactory2() { // override to configure data source if (dataSource2 == null) { - // superclass will lookup from JNDI. - DataSource ds = (DataSource) super.getConnectionFactory2(); + // superclass will lookup from JNDI. + Object obj = super.getConnectionFactory2(); + DataSource ds = null; + if (obj != null) { + if (obj instanceof DataSource) + ds = (DataSource) obj; + else { + Log log = getLog(LOG_JDBC); + if (log.isTraceEnabled()) { + Localizer loc = Localizer.forPackage(JDBCConfigurationImpl.class); + log.trace(loc.get("unknown-datasource", getConnectionFactory2Name(), + obj.getClass().getName())); + } + } + } + if (ds == null) { // the driver name is always required, so if not specified, // then no connection factory 2 diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/conf/localizer.properties b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/conf/localizer.properties index 401cd51bb..edddbfa89 100644 --- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/conf/localizer.properties +++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/conf/localizer.properties @@ -244,3 +244,5 @@ connecting-for-dictionary: OpenJPA will now connect to the database to attempt \ the documentation for available values). map-factory: Using mapping factory "{0}". meta-factory: Using metadata factory "{0}". +unknown-datasource: JNDI lookup for "{0}" returned "{1}", which is not a \ + javax.sql.DataSource object.