gavin wrote:
Note that of course this functionality does not apply if you have access="field" on your identifer property.
I checked the mapping for the identifier property:
Code:
<id name="id" type="int" column="ID" unsaved-value="-1"> <generator class="sequence"/> </id>
Here's a debug dump of running the query. You can clearly see that the
entity association are being resolved by loading from the db.
A point of interest (maybe) is that these objects are all derived from a
base class and mapped using table per class hierarchy, but there's also
a mapping (in another class not used here at all) that contains polymorphic rererences to instances of all these classes using an <any>.
I would not have thought this makes a difference, but....
Thanks again for your input.
08:57:14,640 DEBUG main org.hibernate.impl.SessionImpl - find: from IGRPair where pairID = 17
08:57:14,640 DEBUG main org.hibernate.engine.QueryParameters - named parameters: {}
08:57:14,640 DEBUG main org.hibernate.hql.ast.QueryTranslatorImpl - parse() - HQL: from app.model.beans.IGRPair where pairID = 17
08:57:14,671 DEBUG main org.hibernate.hql.AST - --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| \-[FROM] 'from'
| \-[RANGE] 'RANGE'
| \-[DOT] '.'
| +-[DOT] '.'
| | +-[DOT] '.'
...
| | | | \-[IDENT] 'app'
| | | \-[IDENT] 'model'
| | \-[IDENT] 'beans'
| \-[IDENT] 'IGRPair'
\-[WHERE] 'where'
\-[EQ] '='
+-[IDENT] 'pairID'
\-[NUM_INT] '17'
08:57:14,671 DEBUG main org.hibernate.hql.ast.ErrorCounter - throwQueryException() : no errors
08:57:14,671 DEBUG main org.hibernate.hql.antlr.HqlSqlBaseWalker - query() << begin, level = 1
08:57:14,671 DEBUG main org.hibernate.hql.ast.FromElement - FromClause{level=1} : app.model.beans.IGRPair (no alias) -> igrpair0_
08:57:14,671 DEBUG main org.hibernate.hql.ast.FromReferenceNode - Resolved : pairID -> igrpair0_.PAIR_ID
08:57:14,671 DEBUG main org.hibernate.hql.antlr.HqlSqlBaseWalker - query() : finishing up , level = 1
08:57:14,687 DEBUG main org.hibernate.hql.ast.HqlSqlWalker - processQuery() : ( SELECT ( FromClause{level=1} IGR_PAIR igrpair0_ ) ( where ( = igrpair0_.PAIR_ID 17 ) ) )
08:57:14,687 DEBUG main org.hibernate.hql.ast.HqlSqlWalker - Derived SELECT clause created.
08:57:14,687 DEBUG main org.hibernate.hql.ast.JoinProcessor - Using FROM fragment [IGR_PAIR igrpair0_]
08:57:14,687 DEBUG main org.hibernate.hql.antlr.HqlSqlBaseWalker - query() >> end, level = 1
08:57:14,703 DEBUG main org.hibernate.hql.AST - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (IGR_PAIR)
+-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
| +-[SELECT_EXPR] SelectExpressionImpl: 'igrpair0_.ID as ID' {FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=IGR_PAIR,tableAlias=igrpair0_,colums={,className=app.model.beans.IGRPair}}}
| \-[SQL_TOKEN] SqlFragment: 'igrpair0_.VERSION as VERSION9_, igrpair0_.NAME as NAME9_, igrpair0_.CONFIG_STATE as CONFIG5_9_, igrpair0_.PROJECT_ID as PROJECT6_9_, igrpair0_.IGR_A_ID as IGR7_9_, igrpair0_.IGR_B_ID as IGR8_9_, igrpair0_.PAIR_ID as PAIR9_9_'
+-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[], fromElementByTableAlias=[igrpair0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
| \-[FROM_FRAGMENT] FromElement: 'IGR_PAIR igrpair0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=IGR_PAIR,tableAlias=igrpair0_,colums={,className=app.model.beans.IGRPair}}
\-[WHERE] SqlNode: 'where'
\-[EQ] SqlNode: '='
+-[SQL_TOKEN] IdentNode: 'igrpair0_.PAIR_ID' {originalText=pairID}
\-[NUM_INT] LiteralNode: '17'
08:57:14,703 DEBUG main org.hibernate.hql.ast.ErrorCounter - throwQueryException() : no errors
08:57:14,703 DEBUG main org.hibernate.hql.ast.QueryTranslatorImpl - HQL: from app.model.beans.IGRPair where pairID = 17
08:57:14,703 DEBUG main org.hibernate.hql.ast.QueryTranslatorImpl - SQL: select igrpair0_.ID as ID, igrpair0_.VERSION as VERSION9_, igrpair0_.NAME as NAME9_, igrpair0_.CONFIG_STATE as CONFIG5_9_, igrpair0_.PROJECT_ID as PROJECT6_9_, igrpair0_.IGR_A_ID as IGR7_9_, igrpair0_.IGR_B_ID as IGR8_9_, igrpair0_.PAIR_ID as PAIR9_9_ from IGR_PAIR igrpair0_ where igrpair0_.PAIR_ID=17
08:57:14,703 DEBUG main org.hibernate.hql.ast.ErrorCounter - throwQueryException() : no errors
08:57:14,703 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
08:57:14,703 DEBUG main org.hibernate.SQL - select igrpair0_.ID as ID, igrpair0_.VERSION as VERSION9_, igrpair0_.NAME as NAME9_, igrpair0_.CONFIG_STATE as CONFIG5_9_, igrpair0_.PROJECT_ID as PROJECT6_9_, igrpair0_.IGR_A_ID as IGR7_9_, igrpair0_.IGR_B_ID as IGR8_9_, igrpair0_.PAIR_ID as PAIR9_9_ from IGR_PAIR igrpair0_ where igrpair0_.PAIR_ID=17
08:57:14,718 DEBUG main org.hibernate.jdbc.AbstractBatcher - preparing statement
08:57:14,734 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
08:57:14,734 DEBUG main org.hibernate.loader.Loader - processing result set
08:57:14,734 DEBUG main org.hibernate.loader.Loader - result set row: 0
08:57:14,734 DEBUG main org.hibernate.loader.Loader - result row: EntityKey[app.model.beans.IGRPair#1265]
08:57:14,750 DEBUG main org.hibernate.loader.Loader - Initializing object from ResultSet: [app.model.beans.IGRPair#1265]
08:57:14,750 DEBUG main org.hibernate.persister.entity.BasicEntityPersister - Hydrating entity: [app.model.beans.IGRPair#1265]
08:57:14,750 DEBUG main org.hibernate.engine.TwoPhaseLoad - Version: 1
08:57:14,750 DEBUG main org.hibernate.loader.Loader - done processing result set (1 rows)
08:57:14,750 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
08:57:14,750 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
08:57:14,750 DEBUG main org.hibernate.jdbc.AbstractBatcher - closing statement
08:57:14,750 DEBUG main org.hibernate.loader.Loader - total objects hydrated: 1
08:57:14,750 DEBUG main org.hibernate.engine.TwoPhaseLoad - resolving associations for [app.model.beans.IGRPair#1265]
08:57:14,750 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - loading entity: [app.model.beans.IGR#1266]
08:57:14,750 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [app.model.beans.IGR#1266]
08:57:14,750 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - object not resolved in any cache: [app.model.beans.IGR#1266]
08:57:14,750 DEBUG main org.hibernate.persister.entity.BasicEntityPersister - Materializing entity: [app.model.beans.IGR#1266]
08:57:14,750 DEBUG main org.hibernate.loader.Loader - loading entity: [app.model.beans.IGR#1266]
08:57:14,750 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
08:57:14,750 DEBUG main org.hibernate.SQL - select igr0_.ID as ID0_, igr0_.VERSION as VERSION2_0_, igr0_.NAME as NAME2_0_, igr0_.CONFIG_STATE as CONFIG5_2_0_, igr0_.PROJECT_ID as PROJECT6_2_0_, igr0_.REGION_ID as REGION7_2_0_, igr0_.REGIONAL_ID as REGIONAL8_2_0_, igr0_.MANUFACTURER as MANUFACT9_2_0_, igr0_.ROLE as ROLE2_0_, igr0_.MGMT_NAME as MGMT11_2_0_, igr0_.MGMT_PASSWORD as MGMT12_2_0_, igr0_.SNMP_NAME as SNMP13_2_0_, igr0_.SNMP_PASSWORD as SNMP14_2_0_, igr0_.TELNET_NAME as TELNET15_2_0_, igr0_.TELNET_PASSWORD as TELNET16_2_0_, igr0_.MGMT_ADDR as MGMT17_2_0_, igr0_.OSPF_ADDR as OSPF18_2_0_, igr0_.OSPF_NMSK as OSPF19_2_0_, igr0_.ALIAS as ALIAS2_0_, igr0_.CONFIG_LEVEL as CONFIG21_2_0_, igr0_.CONFIG_PWD as CONFIG22_2_0_, igr0_.FIRMWARE_VER as FIRMWARE23_2_0_, igr0_.SOURCE_SCRIPT as SOURCE24_2_0_ from NE igr0_ where igr0_.ID=? and igr0_.OBJ_TYPE='IGR'
08:57:14,781 DEBUG main org.hibernate.jdbc.AbstractBatcher - preparing statement
08:57:14,796 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
08:57:14,796 DEBUG main org.hibernate.loader.Loader - processing result set
08:57:14,796 DEBUG main org.hibernate.loader.Loader - result set row: 0
08:57:14,796 DEBUG main org.hibernate.loader.Loader - result row: EntityKey[app.model.beans.IGR#1266]
08:57:14,796 DEBUG main org.hibernate.loader.Loader - Initializing object from ResultSet: [app.model.beans.IGR#1266]
08:57:14,796 DEBUG main org.hibernate.persister.entity.BasicEntityPersister - Hydrating entity: [app.model.beans.IGR#1266]
08:57:14,796 DEBUG main org.hibernate.engine.TwoPhaseLoad - Version: 0
08:57:14,796 DEBUG main org.hibernate.loader.Loader - done processing result set (1 rows)
08:57:14,796 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
08:57:14,796 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
08:57:14,796 DEBUG main org.hibernate.jdbc.AbstractBatcher - closing statement
08:57:14,812 DEBUG main org.hibernate.loader.Loader - total objects hydrated: 1
08:57:14,812 DEBUG main org.hibernate.engine.TwoPhaseLoad - resolving associations for [app.model.beans.IGR#1266]
08:57:14,812 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - loading entity: [app.model.beans.Region#1264]
08:57:14,812 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [app.model.beans.Region#1264]
08:57:14,812 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - object not resolved in any cache: [app.model.beans.Region#1264]
08:57:14,812 DEBUG main org.hibernate.persister.entity.BasicEntityPersister - Materializing entity: [app.model.beans.Region#1264]
08:57:14,812 DEBUG main org.hibernate.loader.Loader - loading entity: [app.model.beans.Region#1264]
08:57:14,812 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
08:57:14,812 DEBUG main org.hibernate.SQL - select region0_.ID as ID0_, region0_.CODE as CODE1_0_, region0_.NAME as NAME1_0_, region0_.NOTES as NOTES1_0_ from REGION region0_ where region0_.ID=?
08:57:14,812 DEBUG main org.hibernate.jdbc.AbstractBatcher - preparing statement
08:57:14,828 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
08:57:14,828 DEBUG main org.hibernate.loader.Loader - processing result set
08:57:14,843 DEBUG main org.hibernate.loader.Loader - result set row: 0
08:57:14,843 DEBUG main org.hibernate.loader.Loader - result row: EntityKey[app.model.beans.Region#1264]
08:57:14,843 DEBUG main org.hibernate.loader.Loader - Initializing object from ResultSet: [app.model.beans.Region#1264]
08:57:14,843 DEBUG main org.hibernate.persister.entity.BasicEntityPersister - Hydrating entity: [app.model.beans.Region#1264]
08:57:14,843 DEBUG main org.hibernate.loader.Loader - done processing result set (1 rows)
08:57:14,843 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
08:57:14,843 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
08:57:14,843 DEBUG main org.hibernate.jdbc.AbstractBatcher - closing statement
08:57:14,843 DEBUG main org.hibernate.loader.Loader - total objects hydrated: 1
08:57:14,843 DEBUG main org.hibernate.engine.TwoPhaseLoad - resolving associations for [app.model.beans.Region#1264]
08:57:14,843 DEBUG main org.hibernate.engine.TwoPhaseLoad - done materializing entity [app.model.beans.Region#1264]
08:57:14,843 DEBUG main org.hibernate.loader.Loader - done entity load
08:57:14,843 DEBUG main org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[app.model.beans.NE.ports#1266]
08:57:14,843 DEBUG main org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[app.model.beans.NE.vnes#1266]
08:57:14,843 DEBUG main org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[app.model.beans.NE.baseAddresses#1266]
08:57:14,843 DEBUG main org.hibernate.engine.TwoPhaseLoad - done materializing entity [app.model.beans.IGR#1266]
08:57:14,843 DEBUG main org.hibernate.loader.Loader - done entity load
08:57:14,843 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - loading entity: [app.model.beans.IGR#1267]
08:57:14,843 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [app.model.beans.IGR#1267]
08:57:14,843 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - object not resolved in any cache: [app.model.beans.IGR#1267]
08:57:14,843 DEBUG main org.hibernate.persister.entity.BasicEntityPersister - Materializing entity: [app.model.beans.IGR#1267]
08:57:14,859 DEBUG main org.hibernate.loader.Loader - loading entity: [app.model.beans.IGR#1267]
08:57:14,859 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
08:57:14,859 DEBUG main org.hibernate.SQL - select igr0_.ID as ID0_, igr0_.VERSION as VERSION2_0_, igr0_.NAME as NAME2_0_, igr0_.CONFIG_STATE as CONFIG5_2_0_, igr0_.PROJECT_ID as PROJECT6_2_0_, igr0_.REGION_ID as REGION7_2_0_, igr0_.REGIONAL_ID as REGIONAL8_2_0_, igr0_.MANUFACTURER as MANUFACT9_2_0_, igr0_.ROLE as ROLE2_0_, igr0_.MGMT_NAME as MGMT11_2_0_, igr0_.MGMT_PASSWORD as MGMT12_2_0_, igr0_.SNMP_NAME as SNMP13_2_0_, igr0_.SNMP_PASSWORD as SNMP14_2_0_, igr0_.TELNET_NAME as TELNET15_2_0_, igr0_.TELNET_PASSWORD as TELNET16_2_0_, igr0_.MGMT_ADDR as MGMT17_2_0_, igr0_.OSPF_ADDR as OSPF18_2_0_, igr0_.OSPF_NMSK as OSPF19_2_0_, igr0_.ALIAS as ALIAS2_0_, igr0_.CONFIG_LEVEL as CONFIG21_2_0_, igr0_.CONFIG_PWD as CONFIG22_2_0_, igr0_.FIRMWARE_VER as FIRMWARE23_2_0_, igr0_.SOURCE_SCRIPT as SOURCE24_2_0_ from NE igr0_ where igr0_.ID=? and igr0_.OBJ_TYPE='IGR'
08:57:14,875 DEBUG main org.hibernate.jdbc.AbstractBatcher - preparing statement
08:57:14,890 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
08:57:14,890 DEBUG main org.hibernate.loader.Loader - processing result set
08:57:14,890 DEBUG main org.hibernate.loader.Loader - result set row: 0
08:57:14,890 DEBUG main org.hibernate.loader.Loader - result row: EntityKey[app.model.beans.IGR#1267]
08:57:14,890 DEBUG main org.hibernate.loader.Loader - Initializing object from ResultSet: [app.model.beans.IGR#1267]
08:57:14,890 DEBUG main org.hibernate.persister.entity.BasicEntityPersister - Hydrating entity: [app.model.beans.IGR#1267]
08:57:14,890 DEBUG main org.hibernate.engine.TwoPhaseLoad - Version: 0
08:57:14,890 DEBUG main org.hibernate.loader.Loader - done processing result set (1 rows)
08:57:14,890 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
08:57:14,890 DEBUG main org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
08:57:14,890 DEBUG main org.hibernate.jdbc.AbstractBatcher - closing statement
08:57:14,890 DEBUG main org.hibernate.loader.Loader - total objects hydrated: 1
08:57:14,890 DEBUG main org.hibernate.engine.TwoPhaseLoad - resolving associations for [app.model.beans.IGR#1267]
08:57:14,906 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - loading entity: [app.model.beans.Region#1264]
08:57:14,906 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [app.model.beans.Region#1264]
08:57:14,906 DEBUG main org.hibernate.event.def.DefaultLoadEventListener - resolved object in session cache: [app.model.beans.Region#1264]
08:57:14,906 DEBUG main org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[app.model.beans.NE.ports#1267]
08:57:14,906 DEBUG main org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[app.model.beans.NE.vnes#1267]
08:57:14,906 DEBUG main org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[app.model.beans.NE.baseAddresses#1267]
08:57:14,906 DEBUG main org.hibernate.engine.TwoPhaseLoad - done materializing entity [app.model.beans.IGR#1267]
08:57:14,906 DEBUG main org.hibernate.loader.Loader - done entity load
08:57:14,906 DEBUG main org.hibernate.engine.TwoPhaseLoad - done materializing entity [app.model.beans.IGRPair#1265]
08:57:14,906 DEBUG main org.hibernate.engine.PersistenceContext - initializing non-lazy collections