[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2352?page=all ]
Gail Badner updated HHH-2352:
-----------------------------
Attachment: testcase.tgz
I have attached a test case that reproduces this and several related issues.
In particular, it reproduces the following:
1) When using Session.load() to load an Item object with an ID that is the same as a
Client object that is already in the current session, the Client object is returned. When
Session.get() is used, null is (correctly) returned. The behavior is the same with and
without using a second-level cache.
2) When using Session.get() to load an Item object with an ID that is the same as a Client
object that was cached in a second-level cache in a previous session, the Client object is
returned. A check using instanceof before assigning the returned object to an Item
variable can be used to avert a ClassCastException.
3) When using Session.load() to load an Item object with an ID that is the same as a
Client object that was cached in a second-level cache in a previous session, an Item proxy
is returned. A ClassCastException is thrown when the proxy is initialized, since it is
(incorrectly) a Client object. Checking the return value before initializing the proxy
does not help since the the proxy is of type Item.
As mentioned earlier, using a Criteria or HQL query is a good workaround for this issue.
Gail Badner
SourceLabs -
http://www.sourcelabs.com
Dependable Open Source Systems
ClassCastException in Session.get()
-----------------------------------
Key: HHH-2352
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2352
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.1
Environment: Hibernate 3.2.1
Reporter: Alexey Romanchuk
Priority: Critical
Attachments: testcase.tgz
We have inheritance with joined-subclass mapping. Imagine that we have parent class -
BaseObject and two subclasses - Client and Item. We enable second level cache on
BaseObject.
try to load Client in first session
Client client = ( Client ) s1.get( Client.class, 1851727l );
after this we have this client in second level cache.
Next - load another subclass with same id:
Item item = ( Item ) s2.get( Item.class, 1851727l );
and here we have ClassCastException because hibernate found BaseObject (Client) and
return it instead of null.
The solution is class check in
org.hibernate.event.def.DefaultLoadEventListener.loadFromSecondLevelCache() function. This
is crititcal bug that violates Session API.
--
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