Yet another one-to-many question.....
I'm pretty sure that the mapping is setup correctly since it works but is
very slow.
I have two classes, ELR and TRID with a parent/child relationship with ELR as the parent.
When the session loads a sample ELR, I see the SQL for the ELR followed by the 1000 or so TRID's go past, very slowly. About 2 statements a second.
I tried lazy loading but I'm porting this from a legacy app that knows nothing of the levels below it so when it does elr.getTRIDs(), the session has gone. I don't want to recode the level above to reattach the beans to a new session, so TRIDs need eager loading.
The legacy app takes about 15 seconds to load the TRIDS into cached objects. The hibernate one takes about 10 minutes! I must be doing something wrong.
Thanks for any suggestions,
Tim
Hibernate version:
2.1.7
Mapping documents:
Code:
<hibernate-mapping>
<class name="omnieng.burnbaby.beans.ELR" table="elr" mutable="false">
<id name="name" column="elr_name" type="string">
<generator class="increment"/>
</id>
<set name="trids" inverse="true" lazy="false">
<key>
<column name="elrt_elr_name"/>
</key>
<one-to-many class="omnieng.burnbaby.beans.TRID"/>
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="omnieng.burnbaby.beans.TRID" table="elrtrid" mutable="false">
<composite-id>
<key-property name="id" column="elrt_trid"/>
<key-property name="elrName" column="elrt_elr_name"/>
</composite-id>
<many-to-one name="elr" column="elrt_elr_name" class="omnieng.burnbaby.beans.ELR" insert="false" update="false" outer-join="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Transaction tx = session.beginTransaction();
ELR elr = (ELR)session.get( ELR.class, name );
tx.commit();
Name and version of the database you are using:Oracle 9i
The generated SQL (show_sql=true):Code:
Hibernate: select elr0_.elr_name as elr_name0_ from elr elr0_ where elr0_.elr_name=?
Hibernate: select trids0_.elrt_elr_name as elrt_elr2___, trids0_.elrt_trid as elrt_trid__, trids0_.elrt_trid as elrt_trid0_, trids0_.elrt_elr_name as elrt_elr2_0_ from elrtrid trids0_ where trids0_.elrt_elr_name=?
Hibernate: select trid0_.elrt_trid as elrt_trid1_, trid0_.elrt_elr_name as elrt_elr2_1_, elr1_.elr_name as elr_name0_ from elrtrid trid0_ left outer join elr elr1_ on trid0_.elrt_elr_name=elr1_.elr_name where trid0_.elrt_trid=? and trid0_.elrt_elr_name=?
Hibernate: select trid0_.elrt_trid as elrt_trid1_, trid0_.elrt_elr_name as elrt_elr2_1_, elr1_.elr_name as elr_name0_ from elrtrid trid0_ left outer join elr elr1_ on trid0_.elrt_elr_name=elr1_.elr_name where trid0_.elrt_trid=? and trid0_.elrt_elr_name=?
Hibernate: selec..... and so on
Debug level Hibernate log excerpt:Code:
[DEBUG,SessionImpl] opened session
[DEBUG,JDBCTransaction] begin
[DEBUG,JDBCTransaction] current autocommit status:false
[DEBUG,SessionImpl] loading [omnieng.burnbaby.beans.ELR#MLN1]
[DEBUG,SessionImpl] attempting to resolve [omnieng.burnbaby.beans.ELR#MLN1]
[DEBUG,SessionImpl] object not resolved in any cache [omnieng.burnbaby.beans.ELR#MLN1]
[DEBUG,EntityPersister] Materializing entity: [omnieng.burnbaby.beans.ELR#MLN1]
[DEBUG,BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,SQL] select elr0_.elr_name as elr_name0_ from elr elr0_ where elr0_.elr_name=?
[DEBUG,BatcherImpl] preparing statement
[DEBUG,StringType] binding 'MLN1' to parameter: 1
[DEBUG,Loader] processing result set
[DEBUG,Loader] result row: MLN1
[DEBUG,Loader] Initializing object from ResultSet: MLN1
[DEBUG,Loader] Hydrating entity: omnieng.burnbaby.beans.ELR#MLN1
[DEBUG,Loader] done processing result set (1 rows)
[DEBUG,BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,BatcherImpl] closing statement
[DEBUG,Loader] total objects hydrated: 1
[DEBUG,SessionImpl] resolving associations for [omnieng.burnbaby.beans.ELR#MLN1]
[DEBUG,SessionImpl] creating collection wrapper:[omnieng.burnbaby.beans.ELR.trids#MLN1]
[DEBUG,SessionImpl] done materializing entity [omnieng.burnbaby.beans.ELR#MLN1]
[DEBUG,SessionImpl] initializing non-lazy collections
[DEBUG,SessionImpl] initializing collection [omnieng.burnbaby.beans.ELR.trids#MLN1]
[DEBUG,SessionImpl] checking second-level cache
[DEBUG,SessionImpl] collection not cached
[DEBUG,BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG,SQL] select trids0_.elrt_elr_name as elrt_elr2___, trids0_.elrt_trid as elrt_trid__, trids0_.elrt_trid as elrt_trid0_, trids0_.elrt_elr_name as elrt_elr2_0_ from elrtrid trids0_ where trids0_.elrt_elr_name=?
[DEBUG,BatcherImpl] preparing statement
[DEBUG,StringType] binding 'MLN1' to parameter: 1
[DEBUG,Loader] result set contains (possibly empty) collection: [omnieng.burnbaby.beans.ELR.trids#MLN1]
[DEBUG,SessionImpl] uninitialized collection: initializing
[DEBUG,Loader] processing result set
[DEBUG,StringType] returning '1100' as column: elrt_trid0_
[DEBUG,StringType] returning 'MLN1' as column: elrt_elr2_0_
[DEBUG,Loader] result row: omnieng.burnbaby.beans.TRID@5e7020
[DEBUG,Loader] Initializing object from ResultSet: omnieng.burnbaby.beans.TRID@5e7020
[DEBUG,Loader] Hydrating entity: omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@5e7020
[DEBUG,StringType] returning 'MLN1' as column: elrt_elr2_0_
[DEBUG,StringType] returning 'MLN1' as column: elrt_elr2___
[DEBUG,Loader] found row of collection: [omnieng.burnbaby.beans.ELR.trids#MLN1]
[DEBUG,SessionImpl] reading row
[DEBUG,StringType] returning '1100' as column: elrt_trid__
[DEBUG,StringType] returning 'MLN1' as column: elrt_elr2___
[DEBUG,SessionImpl] loading [omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@135daf]
[DEBUG,SessionImpl] attempting to resolve [omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@135daf]
[DEBUG,SessionImpl] object not resolved in any cache [omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@135daf]
[DEBUG,EntityPersister] Materializing entity: [omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@135daf]
[DEBUG,BatcherImpl] about to open: 1 open PreparedStatements, 1 open ResultSets
[DEBUG,SQL] select trid0_.elrt_trid as elrt_trid1_, trid0_.elrt_elr_name as elrt_elr2_1_, elr1_.elr_name as elr_name0_ from elrtrid trid0_ left outer join elr elr1_ on trid0_.elrt_elr_name=elr1_.elr_name where trid0_.elrt_trid=? and trid0_.elrt_elr_name=?
[DEBUG,BatcherImpl] preparing statement
[DEBUG,StringType] binding '1100' to parameter: 1
[DEBUG,StringType] binding 'MLN1' to parameter: 2
[DEBUG,Loader] processing result set
[DEBUG,StringType] returning 'MLN1' as column: elr_name0_
[DEBUG,Loader] result row: MLN1, omnieng.burnbaby.beans.TRID@135daf
[DEBUG,Loader] Initializing object from ResultSet: omnieng.burnbaby.beans.TRID@135daf
[DEBUG,Loader] Hydrating entity: omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@135daf
[DEBUG,StringType] returning 'MLN1' as column: elrt_elr2_1_
[DEBUG,Loader] done processing result set (1 rows)
[DEBUG,BatcherImpl] done closing: 1 open PreparedStatements, 1 open ResultSets
[DEBUG,BatcherImpl] closing statement
[DEBUG,Loader] total objects hydrated: 1
[DEBUG,SessionImpl] resolving associations for [omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@135daf]
[DEBUG,SessionImpl] loading [omnieng.burnbaby.beans.ELR#MLN1]
[DEBUG,SessionImpl] attempting to resolve [omnieng.burnbaby.beans.ELR#MLN1]
[DEBUG,SessionImpl] resolved object in session cache [omnieng.burnbaby.beans.ELR#MLN1]
[DEBUG,SessionImpl] done materializing entity [omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@31c6ace]
[DEBUG,StringType] returning '1101' as column: elrt_trid0_
[DEBUG,StringType] returning 'MLN1' as column: elrt_elr2_0_
[DEBUG,Loader] result row: omnieng.burnbaby.beans.TRID@1f243d1
[DEBUG,Loader] Initializing object from ResultSet: omnieng.burnbaby.beans.TRID@1f243d1
[DEBUG,Loader] Hydrating entity: omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@1f243d1
[DEBUG,StringType] returning 'MLN1' as column: elrt_elr2_0_
[DEBUG,StringType] returning 'MLN1' as column: elrt_elr2___
[DEBUG,Loader] found row of collection: [omnieng.burnbaby.beans.ELR.trids#MLN1]
[DEBUG,SessionImpl] reading row
[DEBUG,StringType] returning '1101' as column: elrt_trid__
[DEBUG,StringType] returning 'MLN1' as column: elrt_elr2___
[DEBUG,SessionImpl] loading [omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@425eb9]
[DEBUG,SessionImpl] attempting to resolve [omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@425eb9]
[DEBUG,SessionImpl] object not resolved in any cache [omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@425eb9]
[DEBUG,EntityPersister] Materializing entity: [omnieng.burnbaby.beans.TRID#omnieng.burnbaby.beans.TRID@425eb9]
[DEBUG,BatcherImpl] about to open: 1 open PreparedStatements, 1 open ResultSets
[DEBUG,SQL] select trid0_...... and so on