diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java index abf8ca72c..9208395c8 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java @@ -79,7 +79,7 @@ public class DiscriminatorMappingInfo } } if ("null".equalsIgnoreCase(_value)) - return (Discriminator.NULL); + return Discriminator.NULL; // strip quotes if (_value.length() > 0 && _value.charAt(0) == '\'') diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java index b48ea77d2..c8c2eaa2c 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java @@ -93,9 +93,8 @@ public class ValueMapDiscriminatorStrategy if (cls != null) return cls; throw new ClassNotFoundException(_loc.get("unknown-discrim-value", - new Object[]{ str, - disc.getClassMapping().getDescribedType().getName(), - new TreeSet(_vals.keySet()) }).getMessage()); + new Object[]{ str, disc.getClassMapping().getDescribedType(). + getName(), new TreeSet(_vals.keySet()) }).getMessage()); } /** @@ -123,6 +122,8 @@ public class ValueMapDiscriminatorStrategy throw new MetaDataException(_loc.get("no-discrim-value", disc.getClassMapping())); + // we set the value before mapping to use to calculate the template + // column's java type disc.setValue(val); super.map(adapt); } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java index 366f11959..ccf29bfe7 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java @@ -85,8 +85,17 @@ public class OpenJPAPersistence public static BrokerFactory toBrokerFactory(EntityManagerFactory emf) { if (emf == null) return null; - emf = (EntityManagerFactory) - ((OpenJPAEntityManagerFactory) emf).getUserObject(EMF_KEY); + if (!(emf instanceof EntityManagerFactoryImpl)) { + Class c = emf.getClass(); + try { + // either cast here may fail + emf = (EntityManagerFactoryImpl) ((OpenJPAEntityManagerFactory) + emf).getUserObject(EMF_KEY); + } catch (ClassCastException cce) { + throw new ArgumentException(_loc.get + ("cant-convert-brokerfactory", c), null, null, false); + } + } return ((EntityManagerFactoryImpl) emf).getBrokerFactory(); } @@ -122,8 +131,18 @@ public class OpenJPAPersistence public static Broker toBroker(EntityManager em) { if (em == null) return null; - em = (EntityManager) ((OpenJPAEntityManager) em).getUserObject(EM_KEY); - return (em == null) ? null : ((EntityManagerImpl) em).getBroker(); + if (!(em instanceof EntityManagerImpl)) { + Class c = em.getClass(); + try { + // either cast here may fail + em = (EntityManagerImpl) ((OpenJPAEntityManager) em). + getUserObject(EM_KEY); + } catch (ClassCastException cce) { + throw new ArgumentException(_loc.get("cant-convert-broker", c), + null, null, false); + } + } + return ((EntityManagerImpl) em).getBroker(); } /** diff --git a/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties b/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties index 51a541ea3..46c688d54 100644 --- a/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties +++ b/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties @@ -90,6 +90,10 @@ unloadable-provider: WARNING: Unable to load persistence provider "{0}" due \ to "{1}" unrecognized-provider: WARNING: Found unrecognized persistence provider "{0}" \ in place of OpenJPA provider. This provider's properties will not be used. +cant-convert-brokerfactory: Unable to convert EntityManagerFactory of type \ + "{0}" into a BrokerFactory. +cant-convert-broker: Unable to convert EntityManager of type "{0}" into a \ + Broker. EntityManagerFactory-name: EntityManagerFactory implementation EntityManagerFactory-desc: Allows extension of standard \ org.apache.openjpa.persistence.EntityManagerFactoryImpl for custom behavior.