-->
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.  [ 1 post ] 
Author Message
 Post subject: Transactions with JBoss 4.0.2, Hibernate and Struts
PostPosted: Sun Jul 03, 2005 3:04 pm 
Newbie

Joined: Wed Nov 24, 2004 1:08 pm
Posts: 5
Hibernate version:
Using JBoss 4.0.2 with built in Hibernate

I have built a basic non-EJB struts application.

I deploy my Hibernate config as a HAR file. This works fine.

Then I deploy my Struts application as a WAR file.

I've found that I have to explicitly wrap all my Hibernate activity in a JTA transaction, like the example below, or I get NullPointerException from HibernateContext.getSession(xxx).

Is there a simpler way to do this than declaring a JTA transaction in every struts Action? I realise I could put the data manipulation code into EJBs and let the container manage transactions, but the application isn't big enough to justify that.

Is it possible for the HibernateContext.getSession call to initiate a transaction if one isn't already in progress, and complete the transaction automatically when the servlet request processing finishes?

public ActionForward execute(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {

UserTransaction ut;
ActionForward forward;
try {
InitialContext context = new InitialContext();
ut = (UserTransaction) context.lookup("java:comp/UserTransaction");

ut.begin();

Session session = HibernateContext.getSession("java:/hibernate/LeadsSessionFactory");


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

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.