why the hibernateTemplate in Spring cant save data to database?

R

rmn190

with the following code:

public void save(User u) {
if(u!=null)
getHibernateTemplate().save(u);
}

u has not been inserted into database,but with callback,it did,as
following:

public void saveWithCallback(final User u) {
HibernateCallback action = new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Transaction trans = null;
try {
trans = session.beginTransaction();
session.save(u);
trans.commit();
}catch(Exception e) {
e.printStackTrace();
trans.rollback();
}
return null;
}
};
getHibernateTemplate().execute(action);
}

why?
Could you help me with that?
Thanks a lot in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top