Issue Details (XML | Word | Printable)

Key: HHH-219
Type: Bug Bug
Status: Closed Closed
Resolution: Rejected
Priority: Major Major
Assignee: Unassigned
Reporter: Michael Kopp
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

one-to-many to subclass fails

Created: 15/Mar/05 04:37 AM   Updated: 16/Mar/05 12:50 AM
Component/s: core
Affects Version/s: 3.0 rc 1
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. XML File Node.hbm.xml (8 kB)
2. XML File Workflow.hbm.xml (3 kB)
3. Text File workflow.sql (5 kB)



 Description  « Hide
I have a one-to-many mapping to a subclass. When the collection is loaded, all instances of the superclass are selected, thus produced an error.

Here is a small part of the mapping, I will attach the full thing afterwards:

<class name="com.ftisoft.workflow.definition.Workflow" table="FT_O_WFDF" >
        <set name="nodes" inverse="true" cascade="all,delete" >
            <key column="workflow_id"/>
            <one-to-many class="com.ftisoft.workflow.definition.Node" />
        </set>

        <set name="startNodes" cascade="all,delete">
            <key column="workflow_id"/>
            <one-to-many class="com.ftisoft.workflow.definition.StartNode" />
        </set>

        <set name="endNodes" cascade="all,delete">
            <key column="workflow_id"/>
            <one-to-many class="com.ftisoft.workflow.definition.EndNode"/>
        </set>
    </class>
    <class name="com.ftisoft.workflow.definition.Node" table="FT_O_WFND" >
        <subclass name="com.ftisoft.workflow.definition.StartNode" discriminator-value="START" >
...
        </subclass>
        <subclass name="com.ftisoft.workflow.definition.EndNode" discriminator-value="END">
...
        </subclass>


    </class>



 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Michael Kopp added a comment - 15/Mar/05 04:38 AM
SQL

Michael Kopp added a comment - 15/Mar/05 04:38 AM
Workflow hbm

Michael Kopp added a comment - 15/Mar/05 04:39 AM
node hbm

Michael Kopp added a comment - 15/Mar/05 04:40 AM
In my opinion, and according to the documentation, the collection startNodes should only return the subclass StartNode. The Select returns all and thus the lazy loading produces an exception:

2005-03-15 11:23:14,548 [main] DEBUG - initializing collection [com.ftisoft.workflow.definition.Workflow.startNodes#B-0aDCFC2euJC000]
2005-03-15 11:23:14,548 [main] DEBUG - checking second-level cache
2005-03-15 11:23:14,564 [main] DEBUG - collection not cached
2005-03-15 11:23:14,564 [main] DEBUG - batch loading collection: [com.ftisoft.workflow.definition.Workflow.startNodes#B-0aDCFC2euJC000]
2005-03-15 11:23:14,564 [main] DEBUG - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-03-15 11:23:14,579 [main] DEBUG - select startnodes0_.workflow_id as workflow6___, startnodes0_.id as id__, startnodes0_.id as id0_, startnodes0_.name as name0_0_, startnodes0_.description as descript4_0_0_, startnodes0_.classname as classname0_0_, startnodes0_.workflow_id as workflow6_0_0_ from FT_O_WFND startnodes0_ where startnodes0_.workflow_id=?
2005-03-15 11:23:14,595 [main] DEBUG - preparing statement
2005-03-15 11:23:14,595 [main] DEBUG - binding 'B-0aDCFC2euJC000' to parameter: 1
2005-03-15 11:23:14,782 [main] DEBUG - about to open ResultSet (open ResultSets: 0, globally: 0)
2005-03-15 11:23:14,782 [main] DEBUG - result set contains (possibly empty) collection: [com.ftisoft.workflow.definition.Workflow.startNodes#B-0aDCFC2euJC000]
2005-03-15 11:23:14,782 [main] DEBUG - uninitialized collection: initializing
2005-03-15 11:23:14,798 [main] DEBUG - processing result set
2005-03-15 11:23:14,798 [main] DEBUG - result set row: 0
2005-03-15 11:23:14,798 [main] DEBUG - returning 'PF0aDCFS2euJC000' as column: id0_
2005-03-15 11:23:14,798 [main] DEBUG - result row: EntityKey[com.ftisoft.workflow.definition.StartNode#PF0aDCFS2euJC000]
2005-03-15 11:23:14,814 [main] DEBUG - about to close ResultSet (open ResultSets: 1, globally: 1)
2005-03-15 11:23:14,829 [main] DEBUG - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2005-03-15 11:23:14,829 [main] DEBUG - closing statement
2005-03-15 11:23:14,845 [main] ERROR - cannot access loading collection
org.hibernate.LazyInitializationException: cannot access loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:167)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:47)
at org.hibernate.collection.PersistentSet.isEmpty(PersistentSet.java:117)

Michael Kopp added a comment - 15/Mar/05 04:44 AM
I think the select should filter for type='START' right?

Gavin King added a comment - 15/Mar/05 02:20 PM
<discriminator force="true"/>

Do not submit user questions to JIRA. This is for bugs in Hibernate. Use the user forum.

Michael Kopp added a comment - 16/Mar/05 12:23 AM
1. I did search quite a time through the forums. I found several people having the same problem, but non got an answer from the hibernate team.
I checked the documentation about polymorphism limits (9.2) and according to that, my need is straight forward and supported (table-per-class, one-to-many)

2. The thing you are describing is not what I want. at least not according to documentation.

force (optional - defaults to false) "force" Hibernate to specify allowed discriminator values even when retrieving all instances of the root class

Which is not what I do. Please check again my sample (workflow). I do NOT retrieve the Root class (Node) but a subclass (StartNode,EndNode) in the 2 one-to-many associations. Thus the force option should have nothing to do with it!

Gavin King added a comment - 16/Mar/05 12:35 AM
Did you try it?

Michael Kopp added a comment - 16/Mar/05 12:41 AM
Not until now, I will. But if it works, the documentation is wrong.

And do you understand, that in this sample, I should not need any extra configuration? The one-to-many referes to the SubClass. It should therefore not retrieve the root class.

Michael Kopp added a comment - 16/Mar/05 12:50 AM
Ok you are right it works. But why do I need it in the first place? As I said I already specified that I want only the sub-class by using it in the one-to-many relation.