Announcement Announcement Module
Collapse
No announcement yet.
Is HibernateCallback necessary? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is HibernateCallback necessary?

    Hi.

    This is a question regarding what is necessary in the Dao-methods in order to handle the underlying HibernateSession correctly.

    Of course I've been using the HibernateDaoSupport with great success, both the already implemented methods in HobernateTemplate and custom implementations of the HibernateCallback interface.
    As I understand it these handles and closes/flushes the HibernateSession correctly.

    What would the consequences be if I coded a method like:

    Code:
    public void doIt(){
    
    	String str = ....
    	Query q = getHibernateTemplate().createQuery(this.getSessionFactory().openSession(), str);
    	//etc with the query
    	List list = q.list();
    	// etc
    }
    Would this code handle the HibernateSession correctly?
    And if not; are there any tricks for making this work in an easy way?

  • #2
    In your example code, the Session is not closed so you would need to handle this manully yourself. Using HibernateCallback Spring handles all resource management for you plus integration with the Spring Hibernate infrastructure. The easiest way to achieve what you want to do is to use HibernateCallback.

    Rob

    Comment


    • #3
      Another point: the hibernate template transforms hibernate's checked exceptions into spring's unchecked ones.

      Comment


      • #4
        Thanks, that was helpful info. I think I'll continue with the Callback..

        Comment

        Working...
        X