Hi!
emmanuel wrote:
2. is definetly the thing to do and not using relation in hibernate sounds really strance, like driving the highway using a 747 (a non-sense). What is you pb about serialization ? Any specific questions ?
Well, first it is not so black-and-white. Making DTO's is not really my idea:
http://www.hibernate.org/124.html
I have seen it quite many times on different pages/postings related to Hibernate.
About serialization:
* Type:
class X {
Long getId();
String getName();
X getParent();
Y getY();
}
* Operation in EJB:
X loadX(id) {
X x = (X)session.get(id, X.class);
x.getY(); // What changes if i remove this line?
x.getY().getName(); // And this?
x.getParent(); // And this?
return x;
}
saveX(X x) {
}
* Operation in web/client:
X x = ejb.loadX(xId); // What object network did i just receive?
x.getY().getId(); // What happens here?
x.getY().getName(); // And here?
x.getParent().getParent().getParent(); // And here?
x.setName("sxx");
Y y = ejb.getY(yId);
x.setY(y); // If I only wanted to change a relation between X & Y without modifying Y, why do I have to load Y?
y.setName("x");
ejb.saveX(x); // What object network did I just send back?
Now regarding 747: basicly, from the viewpoint of EJB interface, what I really need is not an object model, but relational model. I need to pass around records which have foreign keys and stuff. Can You suggest a better tool to do the job?
Yes, I don't use 70% of Hibernate capabilities, but if it does the job without the overhead, who cares? Besides, if situation changes (which I doubt) I can start using objects.
Now, theoretically speaking: what are advantages of passing around real objects instead of (relational)records aka DTO? I understand, that when Your data access layer is in the same web container as the servlet itself - it is convenient to use real objects. But why would I want to do this way when working with EJB over remote inerfaces?
OM