wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Spring->Hibernate->JPA design question... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Spring->Hibernate->JPA design question..." Watch "Spring->Hibernate->JPA design question..." New topic
Author

Spring->Hibernate->JPA design question...

Alex Paransky J
Greenhorn

Joined: May 23, 2011
Posts: 11
I am just starting with these technologies and I am coming from older EJB systems. I created a data model using POJO and mapped it to the database tables. Created repositories and wrapped everything in a Service which has transactional annotations. My relationships are mostly lazy so that I don't suck up the entire database when retrieving one object. So far, so good. I like it.

The question I have is regarding returning my POJO model beans from the Service interface.

If the service is accessed locally, then trying to read collections which have not been "touched" during transaction kicks off the Lazy loading process which by that time no longer has the session causing an exception to happen. Meanwhile most of the examples I saw tend to declare the POJO model objects as implementing Serializable which seems to indicate that no special Data Transfer objects are needed and the model POJOs can be used directly by the client of the Service.

Of course in the old EJB model we never returned the EntityBean to the client outside of the SessionBean and always used Data Transfer Objects to communicate between external client and internal EntityBeans through the SessionBeans. Is this still the case with Spring->Hibernate->JPA? According to my short experience with this technology it seems that Data Transfer Objects still should be used as a main interface between the client and the Service.

Is there something that I am missing?

Thanks.
-AP_
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Spring->Hibernate->JPA design question...
 
Similar Threads
JSP to connect to a web service
Newbie Question: What's the relationship between JPA and EJB?
Retired Patterns
Facades, Entity Beans and DAOs
examples using SEAM + pojo + Tomcat