Best way to show hibernate query results in jsp

Since the "open session in view" pattern has some drawbacks (see Why is Hibernate Open Session in View considered bad practice? ), I'm wondering what is considered the best approach when displaying the results of a sleeping request to a jsp page?

One of the methods I was thinking about is putting a java.util.list object in the request and outputting the content to the jsp page. Are there other / better methods?

+3


source to share


1 answer


The best way is to use DTO projections for your custom views. This way, you can avoid LazyInitializationExceptions

and make sure you only get what you need in a certain way. From a performance standpoint, nothing beats the SQL projection.

The DTO projection looks like this:



select new my.package.UserInfo(u.name, u.age, u.gender)
from Users u

      

+1


source







All Articles