Plugins (1083)


Training and Consulting (44)



EPIC Poll

What is your favourite developer portal?

[ Results | Polls ]

Votes: 540
Comments: 0

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
frankiestd168
Post subject: Can retrieve, but not update, commit the Transaction  PostPosted: 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
 
 View user's profile Send private message  
Reply with quote Back to top
frankiestd168
Post subject:   PostPosted: 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?
 
 View user's profile Send private message  
Reply with quote Back to top
frankiestd168
Post subject:   PostPosted: 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();
 
 View user's profile Send private message  
Reply with quote Back to top
chamarts
Post subject:   PostPosted: 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
 
 View user's profile Send private message  
Reply with quote Back to top
chamarts
Post subject:   PostPosted: 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 ? Sad
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits