gethibernatetemplate().save(object) does not persist data
<p>I have bellow code stuffs and I'm using spring and hibernate</p>

<p>//main method in main class</p>

<pre><code>public static void main(String[] args) {        
        String[] path = new String[]{"applicationContext.xml"};
        ApplicationContext context = new ClassPathXmlApplicationContext(path); 
        serviceObj = (ServiceClassType)context.getBean("serviceBean");
        serviceObj.doTask();  

    }
</code></pre>

<p>//service method in service class</p>

<pre><code>doTask(){
Obj obj=new Obj();
obj.setValue1("value1");
obj.setValue2("value2");
myDao.saveObject(obj);

}
</code></pre>

<p>//in dao class
//scenario #1</p>

<pre><code>saveObject(Obj obj){
gethibernatetemplate().save(obj);
}
</code></pre>

<p>//scenario #2</p>

<pre><code>saveObject(Obj obj){
session = getHibernateTemplate().getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        session.save(obj);
        tx.commit();
}
</code></pre>

<p>***scenario #1 does not persists data but scenario #2 working fine. Can someone explain why? </p>