These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: ObjectNotFoundException on third level many-to-one reference
PostPosted: Fri Jan 21, 2005 12:10 am 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
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


Top
 Profile  
 
 Post subject: Stack trace
PostPosted: Fri Jan 21, 2005 12:49 am 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Sorry, here is the proper stack trace:
Code:
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: 0, of class: com.xyz.domain.User
   org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27)
   org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:718)
   org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
   org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
   org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:115)
   com.xyz.domain.User$$EnhancerByCGLIB$$1cad566b.getContact()
   sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:324)
   org.apache.taglibs.standard.lang.jstl.ArraySuffix.evaluate(ArraySuffix.java:278)
   org.apache.taglibs.standard.lang.jstl.ComplexValue.evaluate(ComplexValue.java:107)
   org.apache.taglibs.standard.lang.jstl.ELEvaluator.evaluate(ELEvaluator.java:204)
   org.apache.taglibs.standard.lang.jstl.ELEvaluator.evaluate(ELEvaluator.java:163)
   org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Evaluator.java:101)
   org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Evaluator.java:129)
   org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager.evaluate(ExpressionEvaluatorManager.java:75)
   org.apache.taglibs.standard.tag.el.core.ExpressionUtil.evalNotNull(ExpressionUtil.java:48)
   org.apache.taglibs.standard.tag.el.core.OutTag.evaluateExpressions(OutTag.java:99)
   org.apache.taglibs.standard.tag.el.core.OutTag.doStartTag(OutTag.java:57)
   org.apache.jsp.adminpages.viewDetails_jsp._jspx_meth_c_out_0(viewDetails_jsp.java:341)
   org.apache.jsp.adminpages.viewDetails_jsp._jspx_meth_c_if_1(viewDetails_jsp.java:312)
   org.apache.jsp.adminpages.viewDetails_jsp._jspService(viewDetails_jsp.java:134)
   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:285)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:232)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
   org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:388)
   org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


Top
 Profile  
 
 Post subject: What seems to be happening...
PostPosted: Fri Jan 21, 2005 12:58 am 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
It appears to me that what is happening is that a fictitious value for the referredBy many-to-one is being created for instances of the parent that don't actually have a reference for that field. So rather than the property being null as I think it ought to be Hibernate seems to be creating an "empty" instance that was materialized out of nowhere which of course does not have values for anything.

How do I stop this fake new instance from being created and set on the object?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.