[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1460?page=c...
]
Olaf Lenzmann commented on HHH-1460:
------------------------------------
I was a bit rash - a wrapper a la exists() cannot catch the ClassCastException if it's
a generic method (generics don't compile to code that depends on the parameter
classes, so the actual class cast is done by the VM in the calling non-generic method),
but it can use Class.isAssignableFrom() to check the type of the returned entity. For
EJB3, something like
public <EntityType> EntityType exists( Class<EntityType> entityClass, Object
id ) {
final EntityType entity = entityManager.find( entityClass, id );
if( entity != null && entityClass.isAssignableFrom( entity.getClass() ) )
return true;
else
return false;
}
Inconsistent behavior when using Session.get() with multiple
subclasses
-----------------------------------------------------------------------
Key: HHH-1460
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1460
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.1.2
Environment: Hibernate 3.1.2
HSQLDB 1.8.0.2
Java 1.5.0_05-b05
Reporter: Seth Fitzsimmons
Attachments: ClassCastException.zip
Session.get() loads a cached instance of an alternate subclass with the same PK after
that subclass has been loaded directly (throwing a ClassCastException where null was
expected). When attempting to load it without prior loading, null is returned, as
expected.
Client and Partner both extend person and have discriminator values of 1 and 2,
respectively. There is a single entry in the database (a Client) with a PK of 0.
This should be null:
Partner partner = (Partner) getSession().get(Partner.class, 0);
assertNull(partner);
It is. However, if the Client is loaded first, Hibernate will attempt to return a
Partner (as a Client) where it should not exist:
Client client = (Client) getSession().get(Client.class, 0);
assertNotNull(client);
// this should be null, not return a Client object (resulting in a ClassCastException)
Partner partner = (Partner) getSession().get(Partner.class, 0);
assertNull(partner);
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira