The architectures that you describe don’t shy with its elegancy. However, there are often cases like that in practice. This situation could be handled much better if web services are used or the whole architecture is developed as Service Oriented Architecture (SOA) instead of using remoting. Remember, the first rule in remoting is to try to avoid it if you can. So, whey you have SOA, you don’t have DTOs, rather you have messages. The whole concept is much different then, but you can find more information on the web.I agree with your comments, but sometimes remoting can´t be avoided or the UI can't be plain html files. Suppose that the user interface is developed in C# using .Net technology (for rich clients that can't be based on a web app), and the core app is under JEE. The view need web services facades, core cannot export domain objects with that scenario.
Code:employeeDao.save(employee); //this one is questionable.DAO pattern is a good read. The main reason to use it to DECOUPLE the persistence concern from domain objects. The fact that you know how to retrieve dao is not responsibility of a domain object. This is very basic good practices, so if we don’t agree on that, than we have much different background :-).There is no persistence logic in the domain objects, only a call the the persistance logic. There is nothing wrong with that.
A little knowledge of Hibernate will show that a best practice is to save children objects from the parent. So, in the case above if you save employee object, the desk object will be save as well. You don’t need the call deskDao.save(employee.getDesk());. Again, this is very basic practices for Hibernate and service implementation.Code:EmployeeService{ void fire(Employee employee){ employee.fire(); employeeDao.save(employee); deskDao.save(employee.getDesk()); } }
I am not sure why you have coupling here. For every page, you attach/load the object to Hibernate session and populate/bind the view that you need.
If I have a large object graph that is passed from my service to the web layer and I need to initialize some collections because of their lazy loading nature, then I have a coupling between my service and web layer!!!
Anyway, there are many ways to deal with lazy loading problems - OpenViewSession is the first step. Another way is to use You will still have problems at some points, but there are many ways to solve them. One very elegant way of doing it is to use AOP:
http://jroller.com/page/cenkcivici?e...to_hiber nate
Also, if you have so big problem with lazy initialization, you can have session-per-conversation:
http://www.hibernate.org/42.html
Anyway, there a lot of information about lazy initialization problems out there.
I am not sure what kind of scenario/product, this could happen. It looks to me that in this case again you need to provide services, which send messages to the client, instead of exposing domain object. However, there is a big difference in how you build normal application and how you build a product.Alse when developing products with an open api availble for your clients, would you return Hibernate aware domain objects? What if your client suddenly has a lazyInitException. Well ofcoarse we can in that case pre-init all the lazy data. But other problems like hibernate version or last modification data fields shouldn't be visible to the outside world .... so can't we agree that there is a difference between data you work with in and below the service layer and data we work in in the views?


Reply With Quote


