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

Peter Fassev (JIRA) noreply at atlassian.com
Thu Sep 20 17:15:15 EDT 2007


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