Add a better error message when casting an instance to PersistenceCapable fails due to the PersistenceCapable interface being loaded by two separate ClassLoaders

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@446769 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Marc Prud'hommeaux 2006-09-15 22:12:05 +00:00
parent 65e0a48a81
commit 53dbcdf35c
2 changed files with 16 additions and 0 deletions

View File

@ -4140,6 +4140,18 @@ public class BrokerImpl
if (obj instanceof PersistenceCapable)
return (PersistenceCapable) obj;
// check for difference instances of the PersistenceCapable interface
// and throw a better error that mentions the class loaders
Class[] intfs = obj.getClass().getInterfaces();
for (int i = 0; intfs != null && i < intfs.length; i++) {
if (intfs[i].getName().equals(PersistenceCapable.class.getName())) {
throw new UserException(_loc.get("pc-loader-different",
Exceptions.toString(obj),
PersistenceCapable.class.getClassLoader(),
intfs[i].getClassLoader())).setFailedObject(obj);
}
}
// not enhanced
throw new UserException(_loc.get("pc-cast",
Exceptions.toString(obj))).setFailedObject(obj);

View File

@ -48,6 +48,10 @@ marked-rollback: The transaction cannot be committed, because it was already \
marked for rollback only. The transaction will be rolled back instead.
refresh-flushed: You cannot refresh an instance that has been flushed to the \
data store.
pc-loader-different: Attempt to cast instance "{0}" to PersistenceCapable failed. \
The object implemented org.apache.openjpa.enhance.PersistenceCapable, \
but the instance of that interface was loaded by two different ClassLoaders: \
"{1}" and "{2}".
pc-cast: Attempt to cast instance "{0}" to PersistenceCapable failed. Ensure \
that it has been enhanced.
del-instance: The instance of type "{0}" with oid "{1}" no longer exists in \