Results 1 to 5 of 5

Thread: HibernateTemplate With Transactions

  1. #1
    Join Date
    Sep 2012
    Location
    Hyderabad
    Posts
    3

    Default 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...
    --
    Thanks && Regards
    Srikanth Neerumalla

  2. #2
    Join Date
    May 2011
    Location
    New Delhi, India
    Posts
    157

    Default

    HibernateTemplate is not recommended. Please refer to

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

  3. #3
    Join Date
    Sep 2012
    Location
    Hyderabad
    Posts
    3

    Default

    Thank you.

    do we go for SessionFactory ?
    --
    Thanks && Regards
    Srikanth Neerumalla

  4. #4
    Join Date
    May 2011
    Location
    New Delhi, India
    Posts
    157

    Default

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

  5. #5
    Join Date
    Sep 2012
    Location
    Hyderabad
    Posts
    3

    Default

    Thank you...
    --
    Thanks && Regards
    Srikanth Neerumalla

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •