Hello, how are you? I believe what I am asking should be quick and possible to do, as I am sure I've done it before, I just cant find how I did it now.
I have a table 'person' which is linked to the table 'house' and one person has one house. If I fetched the person object from the database, using option lazy=true in configuration, when I try to do person.getHouse(), i will get a proxy object instead of the real House object.
Code:
public static Person getPersonById(int id) {
Transaction transaction = null;
Session session = HibernateUtil.getSessionFactory()
.getCurrentSession();
transaction = session.beginTransaction();
Person p = session.get(Person.class, id);
transaction.commit();
return p;
}
.....
....
Person p= getPersonById(1);
// in h i will obtain the proxy
House h = p.getHouse();
¿How can I obtain the House object back later? I remember I had to open a session (I closed the session after fetching the person object), and then use Hibernate.initialize(h) or something like this, but I cant get it to work.
Thanks for your time!