-->
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.  [ 2 posts ] 
Author Message
 Post subject: Strange behaviour of: --session.get(class,id)
PostPosted: Wed Apr 11, 2007 8:17 am 
Newbie

Joined: Mon Mar 26, 2007 4:22 am
Posts: 4
Hibernate version: 3.2


Hallo,

I asked this question before, but unfortunately nobody could provide me any hint on this. I think this is an error, since Hibernate shows different behaviour depending on 2nd-level-cache on or off.

Any help would be greatly appreciated!
Andreas
----------------------------------------------------------------------------


I have the following mapping file:


Code:
<hibernate-mapping package="com.demo.pojos">
   <class name="com.demo.pojos.Produkt"
      dynamic-update="true">

      <cache usage="read-only" region="ProduktCache"/>

      <id name="id">
         <column name="ID_TXT" sql-type="CHAR(16)" />
      </id>

        <... several properties ...>


      <union-subclass
         name="com.demo.pojos.ElementarProdukt"
         table="QD01V171">
            <... several properties ...>
      </union-subclass>

      <union-subclass
         name="com.demo.pojos.KombiProdukt"
         table="QD01V151">
            <... several properties ...>
      </union-subclass>

   </class>
</hibernate-mapping>



When I'm not using EHCache the following code runs as expected:


Code:
   IPojo kpPojo = session.get( KombiProdukt.class, produktId );
   IPojo epPojo = session.get( ElementarProdukt.class, produktId );

   if ( kpPojo != null ) {
        // do something with KombiProdukt

   } else if ( epPojo != null ) {
        // do something with ElementarProdukt

   }


(I know this is not very clever code from OO-Perspective but I'm porting an existing project and dont want to change more than necessary).

So when my ID (which is unique across all tables) finds a KombiProdukt or an ElementarProdukt, everything works fine.

BUT:
When I activate EHCache (without changing anything else) it occurs, that sometimes an object of type ElementarProdukt is found by
session.get( KombiProdukt.class, produktId )


In my understanding, the class-Argument in get(Class,Serializable) should prevent exactly this, shouldn't it?

The Onlinehelp says:
"Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. (If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance.) "

It would be great if someone could explain this to me.
Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 5:41 pm 
Beginner
Beginner

Joined: Mon May 21, 2007 5:22 pm
Posts: 27
Location: Salt Lake City
Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. (If the instance, or a proxy for the instance, is already associated with the session, return that instance or proxy.

As javadocs about the session.get() method says above.

So if your cache is enable and you try to get the data from the session.get() method with the specific id and id persists in the session. Will hit the cache first and return the same.

_________________
Try 'N' Enjoy !!
Rahul

If helpful do rating ....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.