Announcement Announcement Module
Collapse
No announcement yet.
HibernateTemplate With Transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HibernateTemplate With Transactions

    I have the following the code in my DAO

    public void setSessionFactory(SessionFactory sessionFactory) {
    this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    I am inserting information in the following ways

    1)

    public void saveAdminInformation(AdminInformation admininfo) {
    hibernateTemplate.saveOrUpdate(admininfo);
    }

    2)

    public void saveAdminInformation(AdminInformation admininfo) {
    Session s = hibernateTemplate.getSessionFactory().openSession( );
    Transaction tx = s.beginTransaction();
    s.saveOrUpdate(admininfo);
    s.flush();
    s.evict(admininfo);
    tx.commit();
    s.close();
    }


    I want to know which one is efficient for coding....
    Thanks in advance...

  • #2
    HibernateTemplate is not recommended. Please refer to

    http://static.springsource.org/sprin...eTemplate.html

    Comment


    • #3
      Thank you.

      do we go for SessionFactory ?

      Comment


      • #4
        You should have a repository/DAO & should be injecting sessionFactory in the repository using Spring.

        Comment


        • #5
          Thank you...

          Comment

          Working...
          X