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.