-->
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.  [ 7 posts ] 
Author Message
 Post subject: org.hibernate.TransactionException: Transaction not successf
PostPosted: Sat Dec 16, 2006 11:24 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
why do I get the following error when I execute this method:


private void updatePerson(Long personId, String firstname) {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

Person aPerson = (Person) session.load(Person.class, personId);

aPerson.setFirstname(firstname);
session.update(aPerson);
session.save(aPerson);

session.getTransaction().commit();
}

exception

org.hibernate.TransactionException: Transaction not successfully started
org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:149)
events.PersonServlet.doGet(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 2:32 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
* Which line does throw this exception?
* Please use the code tags so as to make your posts more readable.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 3:19 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
here is the code that calls this method and throws the exception:

protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

//SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy");

try {
// Begin unit of work
//HibernateUtil.getSessionFactory()
// .getCurrentSession().beginTransaction();

// Write HTML header
PrintWriter out = response.getWriter();
out.println("<html><head><title>Event Manager</title></head><body>");

// Handle actions
if ( "addemailtoperson".equals(request.getParameter("action")) ) {

Long eventTitle = Long.parseLong(request.getParameter("eventTitle"));
String eventDate = request.getParameter("eventDate");

if ( "".equals(eventTitle) || "".equals(eventDate) ) {
out.println("<b><i>Please enter event title and date.</i></b>");
} else {
//createAndStoreEvent(eventTitle, dateFormatter.parse(eventDate));
addEmailToPerson(eventTitle, eventDate);
out.println("<b><i>Added event.</i></b>");
}
}

// Print page
printEventForm(out);
listEvents(out);

// Write HTML footer
out.println("</body></html>");
out.flush();
out.close();

// End unit of work
//HibernateUtil.getSessionFactory()
// .getCurrentSession().getTransaction().commit();

} catch (Exception ex) {
HibernateUtil.getSessionFactory()
.getCurrentSession().getTransaction().rollback();
throw new ServletException(ex);
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 3:19 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
here is the code that calls this method and throws the exception:

protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

//SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy");

try {
// Begin unit of work
HibernateUtil.getSessionFactory()
.getCurrentSession().beginTransaction();

// Write HTML header
PrintWriter out = response.getWriter();
out.println("<html><head><title>Event Manager</title></head><body>");

// Handle actions
if ( "addemailtoperson".equals(request.getParameter("action")) ) {

Long eventTitle = Long.parseLong(request.getParameter("eventTitle"));
String eventDate = request.getParameter("eventDate");

if ( "".equals(eventTitle) || "".equals(eventDate) ) {
out.println("<b><i>Please enter event title and date.</i></b>");
} else {
//createAndStoreEvent(eventTitle, dateFormatter.parse(eventDate));
addEmailToPerson(eventTitle, eventDate);
out.println("<b><i>Added event.</i></b>");
}
}

// Print page
printEventForm(out);
listEvents(out);

// Write HTML footer
out.println("</body></html>");
out.flush();
out.close();

// End unit of work
HibernateUtil.getSessionFactory()
.getCurrentSession().getTransaction().commit();

} catch (Exception ex) {
HibernateUtil.getSessionFactory()
.getCurrentSession().getTransaction().rollback();
throw new ServletException(ex);
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 3:28 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
the problem was that i was beginning and commiting my transaction once in my method and once in my doGet method of my servlet.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 3:45 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
I have list of items in my jsp pages and that are being generated by the following code
and I want to be able to update multiple records if I change one my items in my list since
it is a text box and can be modified....and I want to be able to only update my items on
the list that have been checked with the check box:


Top
 Profile  
 
 Post subject: hibernate returning null in my fields...
PostPosted: Wed Dec 27, 2006 1:26 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
have this field called status and you can enter anything in this field and it is not even required. but for some reason when I get data back from hibernate I get back the value "null" in my field.... why is this happening.. i am using hibernate to retrieve the data...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

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.