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!