-->
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: bug in org.hibernate.engine.EntityKey.equals() ??
PostPosted: Thu Apr 19, 2007 6:29 am 
Newbie

Joined: Thu Apr 19, 2007 3:03 am
Posts: 1
Location: Prague, Czech rep.
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.3 (same problem in 3.2)

Name and version of the database you are using: Mysql 4.1

hi all,
i'll start with listing org.hibernate.engine.EntityKey.equals() implementation:

Code:
   public boolean equals(Object other) {
      EntityKey otherKey = (EntityKey) other;
      return otherKey.rootEntityName.equals(this.rootEntityName) &&
         identifierType.isEqual(otherKey.identifier, this.identifier, entityMode, factory);
   }


let's say we have very simple mapping containing 3 classes
abstract A, A1 extends A, A2 extends A.

A1 and A2 are stored in A1 and A2 tables (mapped as union-subclass), id is taken from hilo generator so table for abstract A is not necessary.

now what happens inside transaction:
Code:
A1 a1=new A1();
session.save(a1);
int id=a1.getId();
session.get(A2.class,id); // here i expect null


transaction is still not closed so no sql was done (except fetching id by hilo generator).
Problem: the last line gets me instance of A1 which is wrong because i wanted A2 class (A1 doesn't extend A2).
when debugging it i saw that on save the instance of A1 was stored into session cache which is HashMap<EntityKey,Object>. on get then the hibernate tried to fetch object from the cache and because of mentioned implementation of org.hibernate.engine.EntityKey.equals() it succeeded.

My question: Is this normal behaviour or bug? :)

thanks for any answer!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 02, 2007 4:19 pm 
Newbie

Joined: Wed Nov 02, 2005 2:48 pm
Posts: 2
Location: Indianapolis
I'm running into a similar problem.

We have a Person class that is extended by both User and Patient classes and Person.personId = User.userId = Patient.patientId

After Patient #550 is loaded into the session/transaction cache, any calls to get or load for User #550 will return the patient #550 because of the above mentioned code in EntityKey.equals().

Can someone speak to why otherKey.rootEntityName.equals(this.rootEntityName) is used instead of just otherKey.entityName.equals(this.entityName) ?

We are mapping User to Person and Patient to Person using joined-subclass elements.

Aside from switching to a discriminator, is there anything I can put in the mapping to either
1) tell hibernate to ignore the session level cache for the Patient and User class or
2) get Person/Patient/User classes to use EntityUniqueKey somehow (because it doesn't seem to have this "feature")
3) add something to the Patient and User mappings to discern them.


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.