Reputation: 3002
Since the "open session in view" pattern have some drawbacks (see Why is Hibernate Open Session in View considered a bad practice?), I am wondering what is considered the best approach in displaying results from a hibernate query to a jsp page?
One method I thought of is put a java.util.list object in the request and output the contents to the jsp page. Are there other/better methods?
Upvotes: 3
Views: 599
Reputation: 153930
The best way is to use DTO projections for your UI views. This way you can avoid LazyInitializationExceptions
and make sure you only fetch what you need in a certain view. From a performance point of view, nothing beats an SQL projection anyway.
The DTO projection looks like this:
select new my.package.UserInfo(u.name, u.age, u.gender)
from Users u
Upvotes: 1