-->
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: 2nd Level Cache changes behaviour of Session.get(class, id)
PostPosted: Tue Mar 27, 2007 9:05 am 
Newbie

Joined: Mon Mar 26, 2007 4:22 am
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2


Hallo,
I'm sure it's not a bug but a feature, but I do not understand the following:

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
Code:
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  
 
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.