I'm trying to map some existing code to a db with hibernate. There are only 2 objects: dcmobjectimpl and it's hashmap of metadata (map). The issue is that the "primary key" on dcmobjectimpl is a property with class of Guid, which I'm converting to a string with a usertype. This column is used as the FK in the map table. In the attached debug log it appears that the map is being loaded properly by hibernate. The issue seems to be that because the fk is not loaded as a Guid, the elements of the map are not added to dcmobjectimpl. If I change Guid to String, the map is loaded correctly onto the dcmObjectImpl. I can't see any method of using a custom type on the FK column of the map table. Any help is appreciated.
Hibernate version: : 3.1.3
Mapping documents:
Code:
<class name="DcmObjectImpl" table="dcmobjectimpl" >
<id name="guid" type="GuidType">
<column name="guid" length="45" />
<generator class="assigned" />
</id>
<property name="classHierarchy" type="ClassHierarchyType">
<column name="classhierarchy" not-null="true">
<comment></comment>
</column>
</property>
<map name="map" inverse="true" cascade="all" lazy="false">
<key>
<column name="dcmobjectguid" length="45" not-null="true" unique="true"/>
</key>
<map-key type="string" column="value" formula="name"/>
<one-to-many class="hib.Map" />
</map>
</class>
<class name="hib.Map" table="map" >
<id type="string">
<column name="guid" length="45" />
<generator class="guid" />
</id>
<many-to-one name="DcmObjectImpl" class="DcmObjectImpl" update="false" insert="true" fetch="select" lazy="false">
<column name="dcmobjectguid" length="45" not-null="true" unique="true"/>
</many-to-one>
<property name="value" type="hib.MetadataValueType">
<column name="value" not-null="true"/>
</property>
<property name="name" type="string">
<column name="name" not-null="true"/>
</property>
</class>
Code between sessionFactory.openSession() and session.close():Code:
List dcmObjectList = session.createQuery("from DcmObjectImpl").list();
Iterator dcmObjectIter = dcmObjectList.iterator();
while( dcmObjectIter.hasNext() ) {
DcmObjectImpl dcmObject = (DcmObjectImpl) dcmObjectIter.next();
Hibernate.initialize(dcmObject.getMap());
StringBuilder builder = new StringBuilder();
builder.append("DcmObject: ");
builder.append(" guid:" + dcmObject.getGuid());
builder.append(" map size: " + dcmObject.getMaps().size());
log.error(builder);
}
Full stack trace of any exception that occurs:No exceptions. The maps are loaded but apparently not associated
Name and version of the database you are using:mysql 5.0
The generated SQL (show_sql=true):Code:
Hibernate: select dcmobjecti0_.guid as guid0_, dcmobjecti0_.classhierarchy as classhie2_0_ from hibpersist.dcmobjectimpl dcmobjecti0_
Hibernate: select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
Hibernate: select dcmobjecti0_.guid as guid0_0_, dcmobjecti0_.classhierarchy as classhie2_0_0_ from hibpersist.dcmobjectimpl dcmobjecti0_ where dcmobjecti0_.guid=?
Hibernate: select dcmobjecti0_.guid as guid0_0_, dcmobjecti0_.classhierarchy as classhie2_0_0_ from hibpersist.dcmobjectimpl dcmobjecti0_ where dcmobjecti0_.guid=?
Hibernate: select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
Hibernate: select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
Hibernate: select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
Hibernate: select dcmobjecti0_.guid as guid0_0_, dcmobjecti0_.classhierarchy as classhie2_0_0_ from hibpersist.dcmobjectimpl dcmobjecti0_ where dcmobjecti0_.guid=?
Hibernate: select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
Hibernate: select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
Hibernate: select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
Hibernate: select dcmobjecti0_.guid as guid0_0_, dcmobjecti0_.classhierarchy as classhie2_0_0_ from hibpersist.dcmobjectimpl dcmobjecti0_ where dcmobjecti0_.guid=?
Hibernate: select dcmobjecti0_.guid as guid0_0_, dcmobjecti0_.classhierarchy as classhie2_0_0_ from hibpersist.dcmobjectimpl dcmobjecti0_ where dcmobjecti0_.guid=?
Hibernate: select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
Hibernate: select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
Debug level Hibernate log excerpt:The debug log through the loading if the first entity:
Code:
0 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.1.3
...
3281 [main] DEBUG org.hibernate.hql.ast.QueryTranslatorImpl - HQL: from DcmObjectImpl
3281 [main] DEBUG org.hibernate.hql.ast.QueryTranslatorImpl - SQL: select dcmobjecti0_.guid as guid0_, dcmobjecti0_.classhierarchy as classhie2_0_ from hibpersist.dcmobjectimpl dcmobjecti0_
3281 [main] DEBUG org.hibernate.hql.ast.ErrorCounter - throwQueryException() : no errors
3297 [main] DEBUG org.hibernate.engine.query.HQLQueryPlan - HQL param location recognition took 16 mills (from DcmObjectImpl)
3313 [main] DEBUG org.hibernate.engine.query.QueryPlanCache - located HQL query plan in cache (from DcmObjectImpl)
3313 [main] DEBUG org.hibernate.engine.query.HQLQueryPlan - find: from DcmObjectImpl
3313 [main] DEBUG org.hibernate.engine.QueryParameters - named parameters: {}
3313 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
3313 [main] DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
3313 [main] DEBUG org.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
3313 [main] DEBUG org.hibernate.connection.DriverManagerConnectionProvider - using pooled JDBC connection, pool size: 0
3313 [main] DEBUG org.hibernate.SQL - select dcmobjecti0_.guid as guid0_, dcmobjecti0_.classhierarchy as classhie2_0_ from hibpersist.dcmobjectimpl dcmobjecti0_
Hibernate: select dcmobjecti0_.guid as guid0_, dcmobjecti0_.classhierarchy as classhie2_0_ from hibpersist.dcmobjectimpl dcmobjecti0_
3313 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
3344 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
3344 [main] DEBUG org.hibernate.loader.Loader - processing result set
3344 [main] DEBUG org.hibernate.loader.Loader - result set row: 0
3344 [main] DEBUG org.hibernate.loader.Loader - result row: EntityKey[DcmObjectImpl#Guid@453807]
3344 [main] DEBUG org.hibernate.loader.Loader - Initializing object from ResultSet: [DcmObjectImpl#Guid@453807]
3360 [main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Hydrating entity: [DcmObjectImpl#Guid@453807]
3375 [main] DEBUG org.hibernate.loader.Loader - result set row: 1
3375 [main] DEBUG org.hibernate.loader.Loader - result row: EntityKey[DcmObjectImpl#Guid@1e2ca7]
3375 [main] DEBUG org.hibernate.loader.Loader - Initializing object from ResultSet: [DcmObjectImpl#Guid@1e2ca7]
3375 [main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Hydrating entity: [DcmObjectImpl#Guid@1e2ca7]
3375 [main] DEBUG org.hibernate.loader.Loader - result set row: 2
3375 [main] DEBUG org.hibernate.loader.Loader - result row: EntityKey[DcmObjectImpl#Guid@1d1e730]
3375 [main] DEBUG org.hibernate.loader.Loader - Initializing object from ResultSet: [DcmObjectImpl#Guid@1d1e730]
3375 [main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Hydrating entity: [DcmObjectImpl#Guid@1d1e730]
3375 [main] DEBUG org.hibernate.loader.Loader - done processing result set (3 rows)
3375 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
3375 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
3375 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
3375 [main] DEBUG org.hibernate.loader.Loader - total objects hydrated: 3
3375 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [DcmObjectImpl#Guid@453807]
3375 [main] DEBUG org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[DcmObjectImpl.map#Guid@453807]
3391 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - done materializing entity [DcmObjectImpl#Guid@453807]
3391 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [DcmObjectImpl#Guid@1e2ca7]
3391 [main] DEBUG org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[DcmObjectImpl.map#Guid@1e2ca7]
3391 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - done materializing entity [DcmObjectImpl#Guid@1e2ca7]
3391 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [DcmObjectImpl#Guid@1d1e730]
3391 [main] DEBUG org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[DcmObjectImpl.map#Guid@1d1e730]
3391 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - done materializing entity [DcmObjectImpl#Guid@1d1e730]
3391 [main] DEBUG org.hibernate.engine.StatefulPersistenceContext - initializing non-lazy collections
3406 [main] DEBUG org.hibernate.event.def.DefaultInitializeCollectionEventListener - initializing collection [DcmObjectImpl.map#Guid@1d1e730]
3406 [main] DEBUG org.hibernate.event.def.DefaultInitializeCollectionEventListener - checking second-level cache
3406 [main] DEBUG org.hibernate.event.def.DefaultInitializeCollectionEventListener - collection not cached
3406 [main] DEBUG org.hibernate.loader.Loader - loading collection: [DcmObjectImpl.map#Guid@1d1e730]
3406 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
3406 [main] DEBUG org.hibernate.SQL - select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
Hibernate: select map0_.dcmobjectguid as dcmobjec2_1_, map0_.guid as guid1_, map0_.name as formula0_1_, map0_.guid as guid1_0_, map0_.dcmobjectguid as dcmobjec2_1_0_, map0_.value as value1_0_, map0_.name as name1_0_ from hibpersist.map map0_ where map0_.dcmobjectguid=?
3406 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
3406 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
3406 [main] DEBUG org.hibernate.loader.Loader - result set contains (possibly empty) collection: [DcmObjectImpl.map#Guid@1d1e730]
3406 [main] DEBUG org.hibernate.engine.CollectionLoadContext - uninitialized collection: initializing
3406 [main] DEBUG org.hibernate.loader.Loader - processing result set
3406 [main] DEBUG org.hibernate.loader.Loader - result set row: 0
3406 [main] DEBUG org.hibernate.type.StringType - returning '1146081027202' as column: guid1_0_
3406 [main] DEBUG org.hibernate.loader.Loader - result row: EntityKey[hib.Map#1146081027202]
3406 [main] DEBUG org.hibernate.loader.Loader - Initializing object from ResultSet: [hib.Map#1146081027202]
3406 [main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Hydrating entity: [hib.Map#1146081027202]
3422 [main] DEBUG org.hibernate.type.StringType - returning 'DesignerUUID' as column: name1_0_
3422 [main] DEBUG org.hibernate.loader.Loader - found row of collection: [DcmObjectImpl.map#Guid@5d9084]
3422 [main] DEBUG org.hibernate.engine.CollectionLoadContext - new collection: instantiating
3422 [main] DEBUG org.hibernate.type.StringType - returning '1146081027202' as column: guid1_
3422 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - loading entity: [hib.Map#1146081027202]
3422 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [hib.Map#1146081027202]
3422 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - resolved object in session cache: [hib.Map#1146081027202]
3422 [main] DEBUG org.hibernate.type.StringType - returning 'DesignerUUID' as column: formula0_1_
3422 [main] DEBUG org.hibernate.loader.Loader - result set row: 1
3422 [main] DEBUG org.hibernate.type.StringType - returning '1146081027203' as column: guid1_0_
3422 [main] DEBUG org.hibernate.loader.Loader - result row: EntityKey[hib.Map#1146081027203]
3422 [main] DEBUG org.hibernate.loader.Loader - Initializing object from ResultSet: [hib.Map#1146081027203]
3422 [main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Hydrating entity: [hib.Map#1146081027203]
3422 [main] DEBUG org.hibernate.type.StringType - returning 'Label' as column: name1_0_
3422 [main] DEBUG org.hibernate.loader.Loader - found row of collection: [DcmObjectImpl.map#Guid@1774b9b]
3422 [main] DEBUG org.hibernate.engine.CollectionLoadContext - new collection: instantiating
3422 [main] DEBUG org.hibernate.type.StringType - returning '1146081027203' as column: guid1_
3422 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - loading entity: [hib.Map#1146081027203]
3422 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [hib.Map#1146081027203]
3422 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - resolved object in session cache: [hib.Map#1146081027203]
3422 [main] DEBUG org.hibernate.type.StringType - returning 'Label' as column: formula0_1_
3422 [main] DEBUG org.hibernate.loader.Loader - done processing result set (2 rows)
3422 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
3422 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
3422 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
3422 [main] DEBUG org.hibernate.loader.Loader - total objects hydrated: 2
3422 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [hib.Map#1146081027202]
3422 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - loading entity: [DcmObjectImpl#Guid@15a6029]
3422 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [DcmObjectImpl#Guid@15a6029]
3422 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - object not resolved in any cache: [DcmObjectImpl#Guid@15a6029]
3422 [main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Fetching entity: [DcmObjectImpl#Guid@15a6029]
3422 [main] DEBUG org.hibernate.loader.Loader - loading entity: [DcmObjectImpl#Guid@15a6029]
3422 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
3422 [main] DEBUG org.hibernate.SQL - select dcmobjecti0_.guid as guid0_0_, dcmobjecti0_.classhierarchy as classhie2_0_0_ from hibpersist.dcmobjectimpl dcmobjecti0_ where dcmobjecti0_.guid=?
...
DcmObject: guid:3CA095C1-D0D7-CFE1-4EA1-DBEA6DA41354 map size: 0
Thanks,
Greg