hi,
I want to iterate over a collection of elements of a hierarchy, and in the mapping the most general class was used.
I want to do instanceof on these elements to do specific code.
I read on
http://www.hibernate.org/280.html that a visitor pattern is the best solution. But in my case it would brought a lot of overhead. I decided to create a method in all entities that return the element(not proxy).
eg
public Entity getThis(){
return this;
}
but the object returned was the proxy. So I modificated this method to
public void getThis(List lista){
lista.add(this);
}
In this case the list was returned and I could get the element with get(0) on the list.
But my doubt is: if I get the entity off proxy and work with this. What is the problems that I can have.
I know that proxy is used to lazy initialize. But in my tests I get the entity off proxy I had a collection in this entity no initialized(PersistentBag) and when I needed to use this it was lazily initialized.
Whats the importance of the proxy besides this? What problem could I have if I continue in this manner?
thanks