[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2855) Error during a entity collection loading - wrong SQL query generation - missing discriminator condition in the "where" clause for a specific subclass

Graeme Rocher (JIRA) noreply at atlassian.com
Tue Jan 27 04:44:41 EST 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2855?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=32198#action_32198 ] 

Graeme Rocher commented on HHH-2855:
------------------------------------

Can someone tell me what this issue is a duplicate of and how was it resolved. We had a workaround in Grails for the problem where we did:

collection.setWhere(RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME + " = '" + referenced.getFullName() + "'");

However, this is causing another issue at the moment:

http://jira.codehaus.org/browse/GRAILS-3210

Since this issue was marked as resolved I removed the workaround, however it caused the test cases that checked whether this behavior was correct to fail so it seems like the issue is not resolved at all. So if it was not resolved what is the workaround? And if there is no workaround can this issue be re-opened?

> Error during a entity collection loading - wrong SQL query generation - missing discriminator condition in the "where" clause for a specific subclass
> -----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-2855
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2855
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.5
>            Reporter: Peter Fassev
>            Priority: Critical
>         Attachments: testcase.zip
>
>
> There is a problem, when loading a entity collection (bag), when the collection element is a subclass. The query, witch fetches the elements of the collection, does not use the discriminator value of a subclass and thus loads also other elements form different classes. Please look at the simple test case I have provided.
> Here is a simple description:
> Having a base class A with two subclasses AA and AB, the class A has many-to-one connection to another base class B. The class B itself has two different collections (bags), the first contains only AA elements, the second bag BB elements. The classes AA and AB has different integer properties.
> When I try to load an instance of class B, which is connected to some AA and AB instances, and than try to access the list of all connected AA instances, there is an exception, because Hibernate tries to load all AA and AB instances in one and the same AA collection. The exception is actually thrown, because Hibernate tries to instanciate an AA instance from a AB data! This is the case, because the selection query, which is generated automatically by Hibernate, does not use the discriminator value of the AA subclass to load the collection, and thus selects the AA and AB elements from the database.
> WORKAROND: Currently, the only workaround i found is to define a "where" parameter in the hibernate-mapping with for each collection with the appropriated subclass discriminator.

-- 
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