Reputation: 34424
i was looking at advantages and disadvantages of Detached object in hibernate and found the link http://www.careerride.com/Hibernate-advantages-disadvantages-of-detached-objects.aspx.
Advantages:- Detached objects passing can be done across layers upto the presentation layer without using Data Transfer Objects.
Question 1:- If we use Persistent object instead of Detached object and take it to up to presentation layer, will we face some issue?
Question 2:- what is the difference between Detached object and Detached Object?
Upvotes: 1
Views: 2438
Reputation: 714
It really depends on whether you want to use lazy loading of your objects or not. Lazy loading is generally preferable if you have a massively complex schema, where fetching objects eagerly would basically cause you to join multiple tables. In this case, you would load an object and when running a getter on a contained object, Hibernate would run another query.
However, as mentioned by Ken Chan, in order to achieve this in a web application, you'll need to use the OSIV pattern to keep your sessions alive while the view is still active, otherwise you'll get LazyLoadingExceptions.
When using DTOs, you have to fetch the data eagerly, but on the other hand, you don't have to go back to the DB for lazy loads. It really depends on your problem set and requirements.
Upvotes: 2
Reputation: 90427
Question 1:
Using the persistent objects directly in the presentation layer requires you to implement the Open Session in View (OSIV) pattern . Some people love it but some hate it and regards it as the anti-pattern.You can goggle easily about the implementation , pros and cons of this pattern . For example ,this and this
Question 2:
Detached object and Detached Object ? Do you have a typo here?
Upvotes: 1