I know about Hibernate session and transaction. Let's say I have an entity (writing code ad hoc, may contain mistakes):
Code:
public class Order {
...
@ManyToOne(joinColumn="person_id", fetch=FetchType.LAZY)
Person person;
@Basic(fetch=FetchType.LAZY)
String note;
@Basic(fetch=FetchType.LAZY)
@Formula("...")
double price;
...
}
Now, let's say the entity is detached and the lazy attributes (person, note, price) are not initialized. I have a code, which can load @ManyToOne "person" already, just by calling em.find(Person.class, id); where "id" is from org.hibernate.proxy.LazyInitializer.getIdentifier(); So the code is generic for any LAZY @ManyToOne relationship, something like:
Code:
order.setPerson(dao.lazyGet(Person.class, order.getPerson()));
and that's it. However, I do not know, how to initialize "note" and "person" with some kind of such automatic or generic code. I did write a special HQL query for each of such LAZY value. And that's tedious.
Recently, I have made a method
dao.lazyGetValue(Order.class, order.getId(), "note")
which builds an HQL query like "SELECT e.note FROM Order e WHERE e.id=?". I have to search a little bit more, how to omit writing the "note" explicitly. That's not good for refactoring. It maybe be a solution to my question. It's just pity Hibernate has no method for such situations.
Andy