[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1460) Inconsistent behavior when using Session.get() with multiple subclasses

Shawn Windler (JIRA) noreply at atlassian.com
Wed Aug 16 11:24:19 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1460?page=comments#action_23950 ] 

Shawn Windler commented on HHH-1460:
------------------------------------

I downloaded the source for version 3.2 rc2 in order to test this change.
>From a default download and install, the tests returned the following:
840 Tests ran	9 Failures	4 Errors	98.45% Success rate	46.792 Seconds

After the change:
840 Tests ran	16 Failures	29 Errors	94.64% Success Rate	57.565 Seconds

Obviously, this change had a greater impact than I previously had hoped it would.  I'm not sure how to fix all these problems, but hopefully someone with a little more experience with the code and the design can lend some insight.

I'm kind of confused as to how the inheritance would work otherwise.
One mapping file.  Two subclasses in the mapping file, sharing one id.  There doesn't seem to be a good way to make sure a session.get( Class class, Serializable id ) call returns the correct subclass.

> 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.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list