Hibernate version: 3.0 beta1
Mapping documents: (simplified)
Code:
<!-- Contact mapping -->
<class name="com.xyz.domain.Contact" table="contact">
<id name="id">
<generator class="native"/>
</id>
<property name="firstName" column="first_name"/>
<property name="lastName" column="last_name"/>
<property name="middleInitial" column="middle_initial"/>
<!-- ... -->
</class>
<!-- User mapping -->
<class name="com.xyz.domain.User" table="users">
<id name="id">
<generator class="native"/>
</id>
<!-- Note, this is not truly a many to one relationship but the mapping semantics
better match the data model than a one to one which requires matching primary
keys for the user and the contact which would leave gaps in the user keys
since not all contact information is backed by a user. -->
<many-to-one name="contact" class="com.xyz.domain.Contact" column="contact_id" fetch="join" cascade="save-update"/>
<property name="userName" column="user_name"/>
<property name="userPassword" column="user_password"/>
<many-to-one name="referredBy" class="com.xyz.domain.User" column="referred_by" fetch="select" cascade="none"/>
</class>
Code between sessionFactory.openSession() and session.close():Using the threadlocal pattern to keep a session open for a request in order to render objects in JSP's...
The line that causes the failed reference is:
Code:
<c:out value="${user.referredBy.contact.firstName}"/>
Full stack trace of any exception that occurs:An error occurred while getting property "contact" from an instance of class com.xyz.domain.User$$EnhancerByCGLIB$$1cad566b (org.hibernate.ObjectNotFoundException: No row with the given identifier exists: 0, of class: com.xyz.domain.User)
Name and version of the database you are using:MySQL 4.0.15-NT
The generated SQL (show_sql=true):Code:
select this_.id as id1_, this_.contact_id as contact_id8_1_, this_.user_name as user_name8_1_, this_.user_password as user_pas4_8_1_, this_.registered_on as register5_8_1_, this_.referred_by as referred6_8_1_, this_.approved_by as approved7_8_1_, contact1_.id as id0_, contact1_.private as private4_0_, contact1_.first_name as first_name4_0_, contact1_.last_name as last_name4_0_, contact1_.middle_initial as middle_i5_4_0_, contact1_.base_city as base_city4_0_, contact1_.base_province as base_pro7_4_0_, contact1_.base_country as base_cou8_4_0_, contact1_.employment_status as employme9_4_0_, contact1_.skill_keywords as skill_k10_4_0_, contact1_.profession as profession4_0_ from users this_ left outer join contact contact1_ on this_.contact_id=contact1_.id where this_.contact_id=?
Hibernate: select this_.id as id1_, this_.contact_id as contact_id8_1_, this_.user_name as user_name8_1_, this_.user_password as user_pas4_8_1_, this_.registered_on as register5_8_1_, this_.referred_by as referred6_8_1_, this_.approved_by as approved7_8_1_, contact1_.id as id0_, contact1_.private as private4_0_, contact1_.first_name as first_name4_0_, contact1_.last_name as last_name4_0_, contact1_.middle_initial as middle_i5_4_0_, contact1_.base_city as base_city4_0_, contact1_.base_province as base_pro7_4_0_, contact1_.base_country as base_cou8_4_0_, contact1_.employment_status as employme9_4_0_, contact1_.skill_keywords as skill_k10_4_0_, contact1_.profession as profession4_0_ from users this_ left outer join contact contact1_ on this_.contact_id=contact1_.id where this_.contact_id=?
Code:
select user0_.id as id1_, user0_.contact_id as contact_id8_1_, user0_.user_name as user_name8_1_, user0_.user_password as user_pas4_8_1_, user0_.registered_on as register5_8_1_, user0_.referred_by as referred6_8_1_, user0_.approved_by as approved7_8_1_, contact1_.id as id0_, contact1_.private as private4_0_, contact1_.first_name as first_name4_0_, contact1_.last_name as last_name4_0_, contact1_.middle_initial as middle_i5_4_0_, contact1_.base_city as base_city4_0_, contact1_.base_province as base_pro7_4_0_, contact1_.base_country as base_cou8_4_0_, contact1_.employment_status as employme9_4_0_, contact1_.skill_keywords as skill_k10_4_0_, contact1_.profession as profession4_0_ from users user0_ left outer join contact contact1_ on user0_.contact_id=contact1_.id where user0_.id=?
Hibernate: select user0_.id as id1_, user0_.contact_id as contact_id8_1_, user0_.user_name as user_name8_1_, user0_.user_password as user_pas4_8_1_, user0_.registered_on as register5_8_1_, user0_.referred_by as referred6_8_1_, user0_.approved_by as approved7_8_1_, contact1_.id as id0_, contact1_.private as private4_0_, contact1_.first_name as first_name4_0_, contact1_.last_name as last_name4_0_, contact1_.middle_initial as middle_i5_4_0_, contact1_.base_city as base_city4_0_, contact1_.base_province as base_pro7_4_0_, contact1_.base_country as base_cou8_4_0_, contact1_.employment_status as employme9_4_0_, contact1_.skill_keywords as skill_k10_4_0_, contact1_.profession as profession4_0_ from users user0_ left outer join contact contact1_ on user0_.contact_id=contact1_.id where user0_.id=?
Debug level Hibernate log excerpt:Code:
DEBUG SessionImpl:214 - opened session
DEBUG AbstractFlushingEventListener:47 - flushing session
DEBUG AbstractFlushingEventListener:148 - Flushing entities and processing referenced collections
DEBUG AbstractFlushingEventListener:184 - Processing unreferenced collections
DEBUG AbstractFlushingEventListener:198 - Scheduling collection removes/(re)creates/updates
DEBUG AbstractFlushingEventListener:73 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
DEBUG AbstractFlushingEventListener:79 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG DefaultAutoFlushEventListener:52 - Dont need to execute flush
DEBUG AbstractBatcher:252 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG AbstractBatcher:377 - opening JDBC connection
DEBUG SQL:290 - select this_.id as id1_, this_.contact_id as contact_id8_1_, this_.user_name as user_name8_1_, this_.use
r_password as user_pas4_8_1_, this_.registered_on as register5_8_1_, this_.referred_by as referred6_8_1_, this_.approved
_by as approved7_8_1_, contact1_.id as id0_, contact1_.private as private4_0_, contact1_.first_name as first_name4_0_, c
ontact1_.last_name as last_name4_0_, contact1_.middle_initial as middle_i5_4_0_, contact1_.base_city as base_city4_0_, c
ontact1_.base_province as base_pro7_4_0_, contact1_.base_country as base_cou8_4_0_, contact1_.employment_status as emplo
yme9_4_0_, contact1_.skill_keywords as skill_k10_4_0_, contact1_.profession as profession4_0_ from users this_ left oute
r join contact contact1_ on this_.contact_id=contact1_.id where this_.contact_id=?
Hibernate: select this_.id as id1_, this_.contact_id as contact_id8_1_, this_.user_name as user_name8_1_, this_.user_pas
sword as user_pas4_8_1_, this_.registered_on as register5_8_1_, this_.referred_by as referred6_8_1_, this_.approved_by a
s approved7_8_1_, contact1_.id as id0_, contact1_.private as private4_0_, contact1_.first_name as first_name4_0_, contac
t1_.last_name as last_name4_0_, contact1_.middle_initial as middle_i5_4_0_, contact1_.base_city as base_city4_0_, contac
t1_.base_province as base_pro7_4_0_, contact1_.base_country as base_cou8_4_0_, contact1_.employment_status as employme9_
4_0_, contact1_.skill_keywords as skill_k10_4_0_, contact1_.profession as profession4_0_ from users this_ left outer joi
n contact contact1_ on this_.contact_id=contact1_.id where this_.contact_id=?
DEBUG AbstractBatcher:341 - preparing statement
DEBUG IntegerType:46 - binding '7' to parameter: 1
DEBUG AbstractBatcher:268 - about to open ResultSet (open ResultSets: 0, globally: 0)
DEBUG Loader:1097 - Using naked result set
DEBUG Loader:361 - processing result set
DEBUG IntegerType:68 - returning '7' as column: id0_
DEBUG IntegerType:68 - returning '7' as column: id1_
DEBUG Loader:643 - result row: EntityKey[com.xyz.domain.Contact#7], EntityKey[com.xyz.domain.User#7]
DEBUG Loader:785 - Initializing object from ResultSet: EntityKey[com.xyz.domain.Contact#7]
DEBUG BasicEntityPersister:1488 - Hydrating entity: [com.xyz.domain.Contact#7]
DEBUG BooleanType:68 - returning 'false' as column: private4_0_
DEBUG StringType:68 - returning 'Mr' as column: first_name4_0_
DEBUG StringType:68 - returning 'Test' as column: last_name4_0_
DEBUG StringType:68 - returning '' as column: middle_i5_4_0_
DEBUG StringType:68 - returning 'Test' as column: base_city4_0_
DEBUG StringType:68 - returning 'AB' as column: base_pro7_4_0_
DEBUG StringType:68 - returning 'Test' as column: base_cou8_4_0_
DEBUG IntegerType:68 - returning '1' as column: employme9_4_0_
DEBUG StringType:68 - returning 'Test' as column: skill_k10_4_0_
DEBUG StringType:68 - returning 'Testing' as column: profession4_0_
DEBUG Loader:785 - Initializing object from ResultSet: EntityKey[com.xyz.domain.User#7]
DEBUG BasicEntityPersister:1488 - Hydrating entity: [com.xyz.domain.User#7]
DEBUG IntegerType:68 - returning '7' as column: contact_id8_1_
DEBUG StringType:68 - returning 'test' as column: user_name8_1_
DEBUG StringType:68 - returning '7iaw3Ur350mqGo7jwQrpkj9hiYB3Lkc/iBml1JQODbJ6wYX4oOHV+E+IvIh/1nsUNzLDBMxfqa2O
b1f1ACio/w==' as column: user_pas4_8_1_
DEBUG TimestampType:68 - returning '2005-01-20 00:00:00' as column: register5_8_1_
DEBUG IntegerType:68 - returning '0' as column: referred6_8_1_
DEBUG IntegerType:68 - returning '0' as column: approved7_8_1_
DEBUG Loader:381 - done processing result set (1 rows)
DEBUG AbstractBatcher:275 - about to close ResultSet (open ResultSets: 1, globally: 1)
DEBUG AbstractBatcher:260 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG AbstractBatcher:361 - closing statement
DEBUG Loader:424 - total objects hydrated: 2
DEBUG TwoPhaseLoad:79 - resolving associations for [com.xyz.domain.Contact#7]
DEBUG PersistentCollectionType:314 - creating collection wrapper:[com.xyz.domain.Contact.qualifications#7]
DEBUG PersistentCollectionType:314 - creating collection wrapper:[com.xyz.domain.Contact.industries#7]
DEBUG PersistentCollectionType:314 - creating collection wrapper:[com.xyz.domain.Contact.contactInfo#7]
DEBUG PersistentCollectionType:314 - creating collection wrapper:[com.xyz.domain.Contact.privateContacts#7]
DEBUG PersistentCollectionType:314 - creating collection wrapper:[com.xyz.domain.Contact.publicContacts#7]
DEBUG TwoPhaseLoad:137 - done materializing entity [com.xyz.domain.Contact#7]
DEBUG TwoPhaseLoad:79 - resolving associations for [com.xyz.domain.User#7]
DEBUG DefaultLoadEventListener:185 - loading entity: [com.xyz.domain.Contact#7]
DEBUG DefaultLoadEventListener:200 - entity found in session cache
DEBUG DefaultLoadEventListener:291 - attempting to resolve: [com.xyz.domain.Contact#7]
DEBUG DefaultLoadEventListener:300 - resolved object in session cache: [com.xyz.domain.Contact#7]
DEBUG DefaultLoadEventListener:185 - loading entity: [com.xyz.domain.User#0]
DEBUG DefaultLoadEventListener:219 - creating new proxy for entity
DEBUG TwoPhaseLoad:137 - done materializing entity [com.xyz.domain.User#7]
DEBUG PersistentContext:656 - initializing non-lazy collections
DEBUG DefaultLoadEventListener:185 - loading entity: [com.xyz.domain.Contact#7]
DEBUG DefaultLoadEventListener:200 - entity found in session cache
DEBUG DefaultLoadEventListener:291 - attempting to resolve: [com.xyz.domain.Contact#7]
DEBUG DefaultLoadEventListener:300 - resolved object in session cache: [com.xyz.domain.Contact#7]
DEBUG DefaultLoadEventListener:291 - attempting to resolve: [com.xyz.domain.User#0]
DEBUG DefaultLoadEventListener:327 - object not resolved in any cache: [com.xyz.domain.User#0]
DEBUG BasicEntityPersister:2299 - Materializing entity: [com.xyz.domain.User#0]
DEBUG AbstractBatcher:252 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG SQL:290 - select user0_.id as id1_, user0_.contact_id as contact_id8_1_, user0_.user_name as user_name8_1_, user0_
.user_password as user_pas4_8_1_, user0_.registered_on as register5_8_1_, user0_.referred_by as referred6_8_1_, user0_.a
pproved_by as approved7_8_1_, contact1_.id as id0_, contact1_.private as private4_0_, contact1_.first_name as first_name
4_0_, contact1_.last_name as last_name4_0_, contact1_.middle_initial as middle_i5_4_0_, contact1_.base_city as base_city
4_0_, contact1_.base_province as base_pro7_4_0_, contact1_.base_country as base_cou8_4_0_, contact1_.employment_status a
s employme9_4_0_, contact1_.skill_keywords as skill_k10_4_0_, contact1_.profession as profession4_0_ from users user0_ l
eft outer join contact contact1_ on user0_.contact_id=contact1_.id where user0_.id=?
Hibernate: select user0_.id as id1_, user0_.contact_id as contact_id8_1_, user0_.user_name as user_name8_1_, user0_.user
_password as user_pas4_8_1_, user0_.registered_on as register5_8_1_, user0_.referred_by as referred6_8_1_, user0_.approv
ed_by as approved7_8_1_, contact1_.id as id0_, contact1_.private as private4_0_, contact1_.first_name as first_name4_0_,
contact1_.last_name as last_name4_0_, contact1_.middle_initial as middle_i5_4_0_, contact1_.base_city as base_city4_0_,
contact1_.base_province as base_pro7_4_0_, contact1_.base_country as base_cou8_4_0_, contact1_.employment_status as emp
loyme9_4_0_, contact1_.skill_keywords as skill_k10_4_0_, contact1_.profession as profession4_0_ from users user0_ left o
uter join contact contact1_ on user0_.contact_id=contact1_.id where user0_.id=?
DEBUG AbstractBatcher:341 - preparing statement
DEBUG IntegerType:46 - binding '0' to parameter: 1
DEBUG AbstractBatcher:268 - about to open ResultSet (open ResultSets: 0, globally: 0)
DEBUG Loader:1097 - Using naked result set
DEBUG Loader:361 - processing result set
DEBUG Loader:381 - done processing result set (0 rows)
DEBUG AbstractBatcher:275 - about to close ResultSet (open ResultSets: 1, globally: 1)
DEBUG AbstractBatcher:260 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG AbstractBatcher:361 - closing statement
DEBUG Loader:424 - total objects hydrated: 0
DEBUG PersistentContext:656 - initializing non-lazy collections
DEBUG SessionImpl:232 - closing session
DEBUG SessionImpl:311 - disconnecting session
DEBUG AbstractBatcher:392 - closing JDBC connection (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globa
lly: 0)
DEBUG SessionImpl:363 - transaction completion