| Author |
Message |
|
|
Post subject: Can retrieve, but not update, commit the Transaction
Posted: Nov 14, 2006 - 05:46 PM
|
|
Joined: Nov 14, 2006
Posts: 3
|
|
sorry for this basic question...
I tried to test the following sample code...
| Code: |
_RootDAO.initialize();
PersonDAO dao = new PersonDAO();
List people = dao.findAll();
|
Yes, I can successfully retrieve people List from MySQL table.
For save/update..
| Code: |
Long id = new Long(3);
Person person = dao.load(id);
person.setFirstName("Joe");
dao.update(person);
|
but Update/Save is not working. MySQL table is not updated.
How can I commit the update/save ?
I tried to add this code to commit,
| Code: |
Transaction tx = dao.beginTransaction(dao.getSession());
// the above code
tx.commit();
|
but it throws org.hibernate.TransactionException: Transaction not successfully started.
If I set autocommit to true in cfg.xml , then it works.
<property name="hibernate.connection.autocommit">true</property>
but i want to control in the code level..
Can anybody pls help... pls |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Nov 14, 2006 - 06:39 PM
|
|
Joined: Nov 14, 2006
Posts: 3
|
|
| Code: |
_RootDAO.initialize();
PersonDAO dao = new PersonDAO();
Transaction tx = dao.beginTransaction(dao.getSession());
//..
// my update code
//..
dao.commitTransaction(tx);
|
i also try this .. but still.. i got exception..
org.hibernate.TransactionException: Transaction not successfully started
How to start the transaction correctly? |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Nov 16, 2006 - 11:28 AM
|
|
Joined: Nov 14, 2006
Posts: 3
|
|
ok, finally I fixed it.. it works for me..
_RootDAO.initialize();
MyfirstDAO dao = new MyfirstDAO();
Myfirst newperson = new Myfirst();
Transaction tx = dao.beginTransaction(dao.getSession());
newperson.setAddress("aaa");
newperson.setName("bbb");
dao.saveOrUpdate(newperson, dao.getSession());
tx.commit(); |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Nov 07, 2007 - 04:08 AM
|
|
Joined: Nov 07, 2007
Posts: 2
|
|
Hi, I am able to save & update it but I am getting error when I query for findAll. Can anybdy help me with this ?
This is how my code is:
_RootDAO.initialize(config/hibernate-cfg.xml);
List myList = MyDAO.findAll();
and the exception is
org.hibernate.HibernateException: createCriteria is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:297)
at $Proxy0.createCriteria(Unknown Source)
at com.oakton.gsti.lam.dao.base._BaseRootDAO.findAll(_BaseRootDAO.java:315)
at |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Nov 07, 2007 - 11:49 PM
|
|
Joined: Nov 07, 2007
Posts: 2
|
|
is it not supposed to be handled by the generated code ? or do I need to supply explicitly ? then, why was it supplied in update and save ?  |
|
|
| |
|
|
|
 |
|
|
| |