I am creating a new project and I have some doubts about the spring + hibernate management. First of all I want to say that I've been reading a lot and I tried to document myself, but after weeks I am still a bit lost on this topic.
Project configuration
My architecture follows this structure:
JSF Beans --> Facade layer --> Service Layer --> DAO Layer
My hibernate handles all DAOS and is fully integrated with Spring.
- The whole Datasource and Hibernate configuration is done in Spring configuration files, so spring manages everything.
- I use Spring Security to handle the project security.
Everything seems to be well integrated but I still can't find a solid solution to manage Hibernate Sessions.
My first approach was to use OSIV using JSF PhaseListeners, but then I integrated Spring and started using @Transactional annotations on my Service layer.
Here are my questions:
I think everytime @Transactional method is invoked an Hibernate session is opened and closed right? Or am I wrong?
With @Transactional I am sure I am going to run in trouble because Hibernate's Lazy instantiation on the Render response phase, and I don't want to do EAGER fetch. So ...
Is it safe to use OSIV? Or is it really vulnerable to DOS attacks?
Is there a better way to handle Lazy fetching problem than OSIV pattern? I am sure I am missing better patterns, can you throw a little bit of light to the topic?
I didn't post any code because all my questions are basically conceptual on architecture, but if you need any of my code to understand me (I know I am a mess explaining myself), you just have to ask me and I'll post it as soon as I can.
Thank you all!