-->
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.  [ 1 post ] 
Author Message
 Post subject: org.hibernate.ObjectNotFoundException occurs when shouldn't
PostPosted: Wed Apr 14, 2010 3:10 am 
Newbie

Joined: Wed Nov 25, 2009 11:35 am
Posts: 17
Hi everybody

This is about "org.hibernate.ObjectNotFoundException: No row with the given identifier exists" exception. I know why it happens and what to do to avoid it. My problem is that exception occurs when (I suppose) it shouldn't.
I have basic class Payor and inherited Client and Insurance. In DB, each Payor is actually Client or Insur, and I wish child class instance to be created when user calls Payor.get(session), so I do
Code:
public class Payor {
   ...
   public static Payor get(org.hibernate.Session session, java.lang.String pyocode) {
      Client _Client = (Client) session.get(Client.class, pyocode);
      if( _Client != null ) return _Client;
      Insur _Insur = (Insur) session.get(Insur.class, pyocode);
      if( _Insur != null ) return _Insur;
      return (Payor) session.get(Payor.class, pyocode);
   }

As it clear from code above, each table has primary key "pyocode".
This works fine until some other entity having foreign link to Payor.pyocode is loaded. When this happens, exception ObjectNotFoundException appears if there is no Client table record with given pyocode (in same time such Insur record exists):

Code:
Exception in thread "main" org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [scc.ar.model.Client#MCR]
        at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:377)
        at org.hibernate.event.def.DefaultLoadEventListener.returnNarrowedProxy(DefaultLoadEventListener.java:223)
        at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:187)
        at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
        at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
        at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
        at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
        at scc.ar.model.Payor.get(Payor.java:146)
        at scc.ar.test.Tester$Batch.instantiate(Tester.java:236)
        at scc.ar.test.Tester$TabDef.parseXml(Tester.java:156)
        at scc.ar.test.Tester.main(Tester.java:353)


My mapping for Batch link to Payor is
Code:
<class dynamic-update="true" name="Batch" table="Batch">
   ...
   <many-to-one class="Payor" name="btdefpyocode" column="btdefpyocode"/>
   ...


Mapping for Payor, Insurance, Client is
Code:
<class dynamic-update="true" name="Payor" table="Payor">
    <id column="pyocode" name="pyocode" type="string">
      <generator class="assigned"/>
    </id>
    ...
    <joined-subclass dynamic-update="true" name="Insur" table="Insur">
      <key column="inscode"/>
      ...
    </joined-subclass>
    <joined-subclass dynamic-update="true" name="Client" table="Client">
       <key column="cltcode"/>
    </joined-subclass>
  </class>


I just thought this error should appear only on line
Code:
      return (Payor) session.get(Payor.class, pyocode);

and I don't want to put not-found="ignore" property for link coz this checking may be helpful in other places.

Statement for
Code:
Client _Client = (Client) session.get(Client.class, pyocode);
I think is
select Client.*, Payor.* from Payor join Client on (cltcode=pyocode) where pyocode='MCR';
Why does hn think there is no payor with pyocode=MCR after performing this statement?

Or maybe there is some trick I don't know. Please advice!


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

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.