I have the following method for initialize a proxy
public void initialize(Entity owner, String propertyName){
Session session = HibernateFactory.getFactory().getCurrentSession();
Transaction tx = session.beginTransaction();
try {
tx.begin();
session.lock(owner, LockMode.NONE);
Object property = owner.executeGetter(propertyName);
Hibernate.initialize(property);
tx.commit();
} catch (Exception ex){
ex.printStackTrace();
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
}
owner.executeGetter(propertyName) simply gets the referenced object using reflection.
when property is a Collection, initialize works. But when it is another object, it remains the byte enhanced version, with all its attributes uninitialized.
anything I am doing wrong?
|