-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Transaction not successfully started
PostPosted: Tue May 27, 2008 11:17 am 
Newbie

Joined: Tue Jan 22, 2008 11:47 am
Posts: 10
Hibernate 3.1

What does this exception mean? and what can it be the cause of it? I had never seen it before.

It happens when I am going to commit, the program is a quite complex program that gets a lot of data and insert them in the database.

If somebody wants, i can put some concrete code, I am not putting it right now because it would be to big i think :)

This is the exception:

Exception in thread "main" org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:149)
at com.eliop.diana.services.ServicioConsultaReservasTDCs.invoke(ServicioConsultaReservasTDCs.java:244)
at com.eliop.diana.services.ServiciosTPLWSRecuperacionServiceClient.main(ServiciosTPLWSRecuperacionServiceClient.java:80)

Thank you very much in advance.
J.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 3:01 pm 
Newbie

Joined: Tue May 27, 2008 10:11 am
Posts: 7
Such error occurs when you already committed transaction and you try rollback it. For example I saw such wrong code:

Code:
try {
    // create session
    tx = session.beginTransaction();
    // do something
    tx.commit();
} finally {
    tx.rollback();
    // close session
}


One is committing something and then (always!) tries to rollback it. Good (but not the best) code is:
Code:
try {
    // create session
    tx = session.beginTransaction();
    // do something
    tx.commit();
} catch (Exception exp) {
    tx.rollback();
    // close session
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 4:10 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
This error not only comes up when a transaction can't be rolled back, but also when one cannot be started or committed:

JavaDoc for Transaction Exception

http://www.hibernate.org/hib_docs/v3/api/org/hibernate/TransactionException.html

You may want to put your beginTransaction method call in blocks, or place a breakpoint there and see when you hit this problem, be it during a begin, commit, or rollback.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 2:43 am 
Newbie

Joined: Tue Jan 22, 2008 11:47 am
Posts: 10
It happens in a commit, what coult it be the reason?

I am lost because the exception does not give you any information.

Thank you very much!
J.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 5:22 am 
Newbie

Joined: Mon Nov 19, 2007 9:01 am
Posts: 8
I have also seen this when using a Spring transaction manager and then trying to explicitly begin a Hibernate transaction using session.beginTransaction(). In this situation you have to ask the transaction manager for a new transaction, session.beginTransaction() seems to be a no-op.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 11:50 am 
Newbie

Joined: Mon Sep 08, 2008 3:01 am
Posts: 3
I'm facing the same problem. Could anybody show me how to fix it?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 12:34 pm 
Newbie

Joined: Thu Oct 26, 2006 11:50 am
Posts: 17
Location: Chesterfield, VA
Are you using any sort of transaction management like EJB, Spring TX or JTA? If you are letting Hibernate control it, there is no transaction across database calls.


Top
 Profile  
 
 Post subject: Re: Transaction not successfully started
PostPosted: Fri Jun 19, 2009 10:27 am 
Newbie

Joined: Fri Jun 19, 2009 10:17 am
Posts: 1
Hi all,
I was getting same error, when i tries to commit transaction.but i checked my code then i got this solved.
reason was, i was calling another function from one finction, in tht other function i was taking new transaction and commiting that and returning some thing, and after checking that returned value in first function , i was trying to commit first function.
now i avoided making new transaction in 2nd function which gets called from 1st and my problm is solved , only i am creating session object and using that in 2nd function.

when i coomit things from 1st function then 2nd function things which i hav called from 1st function also gets commited..
and my problem has SOLVED ...

I hope this will help u .. and u guys go ahead ...

If u have any more queries plz reply me on tushar.barbhai@gmail.com
I will definetly help u in hibernate ..


Top
 Profile  
 
 Post subject: Re: Transaction not successfully started
PostPosted: Thu Oct 08, 2009 4:52 am 
Newbie

Joined: Thu Oct 08, 2009 4:48 am
Posts: 1
thank you tushar.barbhai... tht wrkd out for me

but we will have to understand ThreadLocal pattern to understand this stuff properly...


Top
 Profile  
 
 Post subject: Re: Transaction not successfully started
PostPosted: Thu Feb 04, 2010 3:45 am 
Newbie

Joined: Wed Feb 03, 2010 11:51 am
Posts: 2
Hi all...I was getting the same error too, but then I realized it happens if commitment comes with a mistake, causing exception, before "transObj.rollback()". When program falls in exception catching -in rollback part- if transaction hasn't been commited yet, it wouldn't create an error like ours. However, if it's committed and then falls in exception, say hello the error. My reason of falling exception was getting end of rows in my table,in database. Then fortunately, it wasn't hard to solve. I hope I could help you...Good luck;)
For visulize, my code was like that:
try{
...
trans.commit(); }

catch(Exception ex){
if(trans!=null) trans.rollback();
S.o.p("Error :" +ex.getMessage());
}



Top
 Profile  
 
 Post subject: Re: Transaction not successfully started
PostPosted: Mon May 17, 2010 2:41 am 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
ys ts ws a rlly hlpfl pst ad hpflly thrs wll njy it smch s mslf :-)


Top
 Profile  
 
 Post subject: Re: Transaction not successfully started
PostPosted: Fri Sep 17, 2010 6:13 am 
Newbie

Joined: Sat Jan 23, 2010 3:05 am
Posts: 2
hi there,

I got same error ("Transaction not successfully started") from my application ,

The scenario was

A(){

B(){
tx =session.beginTransaction();

c(){
hibernate calls happens ( insert , update )here but no begin & commit
}
if(evrything is fine ){
tx.commit
}else{
tx.rollback
}

}

}


i have called method A() from my app it works fine without throwing an error

but when i call method B() from my app it throws the following exception
org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:100)


the only difference between A() & B() is former returns String latter is void type....

Please help ME ASAP

Thanks in advance


Top
 Profile  
 
 Post subject: Re: Transaction not successfully started
PostPosted: Mon Sep 20, 2010 5:40 am 
Newbie

Joined: Sat Jan 23, 2010 3:05 am
Posts: 2
hi guys

the "Transaction not successfully started" problem posted by myself
was solved...

ive changed my commit line of code ( trans.commit ) by following three lines

if(!trans.wasCommitted){

trans.commit;
}

Thanks


Top
 Profile  
 
 Post subject: Re: Transaction not successfully started
PostPosted: Thu Jul 07, 2011 5:16 am 
Newbie

Joined: Thu Jul 07, 2011 5:12 am
Posts: 1
Hi Frnds,
My first post, Well I faced the same problem which was because I forgot to add the session.beginTransaction() line.

Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();

// blah blah

session.save(user);

session.getTransaction().commit();
session.close();


Top
 Profile  
 
 Post subject: Re: Transaction not successfully started
PostPosted: Wed Dec 04, 2013 4:20 am 
Newbie

Joined: Wed Dec 04, 2013 4:13 am
Posts: 1
I get the same error

org.hibernate.TransactionException: Transaction not successfully started

I am searching the cause of the error and the conclusion is because this code is not existed :

session.beginTransaction();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.