Here is some debug output from hibernate I thought that might help. This is another ManyToOne relationship I want to load lazily. However, it's loading it eagerly everytime. I thought it was interesting since it does what I wanted then the TwoPhaseLoad class kicks in and starts trying to load the rest of the relationships.
I can't for the life of me figure out why this TwoPhasedLoad is listening and loading these relationships.
In this case AttachmentEntity has a bidirectional ManyToOne with MessageEntity. MessageEntity has a OneToMany with AttachementEntity that is loaded eagerly. In this log I'm trying to just load the AttachmentEntity, but the MessageEntity is loading as well. Eventhough I've marked the relationship as lazy.
This is really affecting performance in my app.
Code:
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 11815011625
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.transaction.JDBCTransaction - begin
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.springframework.jdbc.datasource.DriverManagerDataSource - Creating new JDBC Connection to [jdbc:derby:emailarchive]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.transaction.JDBCTransaction - current autocommit status: true
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.transaction.JDBCTransaction - disabling autocommit
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.jdbc.JDBCContext - after transaction begin
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.engine.query.QueryPlanCache - located HQL query plan in cache (from AttachmentEntity where id = ? )
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.engine.query.QueryPlanCache - located HQL query plan in cache (from AttachmentEntity where id = ? )
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.engine.query.HQLQueryPlan - find: from AttachmentEntity where id = ?
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.engine.QueryParameters - parameters: [7]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.engine.QueryParameters - named parameters: {}
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.SQL -
select
attachment0_.ID as ID1_,
attachment0_.ATTACHMENT_FILE as ATTACHMENT2_1_,
attachment0_.ATTACHMENT_NAME as ATTACHMENT3_1_,
attachment0_.inline as inline1_,
attachment0_.MESSAGE_ID as MESSAGE6_1_,
attachment0_.CONTENT_TYPE as CONTENT5_1_
from
APP.ATTACHMENTS attachment0_
where
attachment0_.ID=?
Hibernate:
select
attachment0_.ID as ID1_,
attachment0_.ATTACHMENT_FILE as ATTACHMENT2_1_,
attachment0_.ATTACHMENT_NAME as ATTACHMENT3_1_,
attachment0_.inline as inline1_,
attachment0_.MESSAGE_ID as MESSAGE6_1_,
attachment0_.CONTENT_TYPE as CONTENT5_1_
from
APP.ATTACHMENTS attachment0_
where
attachment0_.ID=?
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.type.IntegerType - binding '7' to parameter: 1
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.loader.Loader - processing result set
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.loader.Loader - result set row: 0
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.type.IntegerType - returning '7' as column: ID1_
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.emailarchive.entity.AttachmentEntity#7]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.loader.Loader - Initializing object from ResultSet: [com.emailarchive.entity.AttachmentEntity#7]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Hydrating entity: [com.emailarchive.entity.AttachmentEntity#7]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.type.StringType - returning 'D:\dev\src\emailarchive\server\data\data21041.gif' as column: ATTACHMENT2_1_
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.type.StringType - returning 'who-broke-the-build.gif' as column: ATTACHMENT3_1_
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.type.BooleanType - returning 'false' as column: inline1_
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.type.IntegerType - returning '146' as column: MESSAGE6_1_
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.type.StringType - returning 'image/gif; name=who-broke-the-build.gif' as column: CONTENT5_1_
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.loader.Loader - done processing result set (1 rows)
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.loader.Loader - total objects hydrated: 1
----------------HERE IS THE TWO PHASE LOAD KICKING IN-------------
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [com.emailarchive.entity.AttachmentEntity#7]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.event.def.DefaultLoadEventListener - loading entity: [com.emailarchive.entity.MessageEntity#146]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [com.emailarchive.entity.MessageEntity#146]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.event.def.DefaultLoadEventListener - object not resolved in any cache: [com.emailarchive.entity.MessageEntity#146]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Fetching entity: [com.emailarchive.entity.MessageEntity#146]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.loader.Loader - loading entity: [com.emailarchive.entity.MessageEntity#146]
2007-06-10 14:46:02,540 [btpool0-6] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2007-06-10 14:46:02,556 [btpool0-6] DEBUG org.hibernate.SQL -