Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:03:33+00:00 2026-05-11T07:03:33+00:00

I have a stateless bean something like: @Stateless public class MyStatelessBean implements MyStatelessLocal, MyStatelessRemote

  • 0

I have a stateless bean something like:

@Stateless public class MyStatelessBean implements MyStatelessLocal, MyStatelessRemote {     @PersistenceContext(unitName='myPC')     private EntityManager mgr;      @TransationAttribute(TransactionAttributeType.SUPPORTED)     public void processObjects(List<Object> objs) {         // this method just processes the data; no need for a transaction         for(Object obj : objs) {             this.process(obj);         }     }      @TransationAttribute(TransactionAttributeType.REQUIRES_NEW)     public void process(Object obj) {         // do some work with obj that must be in the scope of a transaction          this.mgr.merge(obj);         // ...         this.mgr.merge(obj);         // ...         this.mgr.flush();     } } 

The typically usage then is the client would call processObjects(…), which doesn’t actually interact with the entity manager. It does what it needs to do and calls process(…) individually for each object to process. The duration of process(…) is relatively short, but processObjects(…) could take a very long time to run through everything. Therefore I don’t want it to maintain an open transaction. I do need the individual process(…) operations to operate within their own transaction. This should be a new transaction for every call. Lastly I’d like to keep the option open for the client to call process(…) directly.

I’ve tried a number of different transaction types: never, not supported, supported (on processObjects) and required, requires new (on process) but I get TransactionRequiredException every time merge() is called.

I’ve been able to make it work by splitting up the methods into two different beans:

@Stateless @TransationAttribute(TransactionAttributeType.NOT_SUPPORTED) public class MyStatelessBean1 implements MyStatelessLocal1, MyStatelessRemote1 {     @EJB     private MyStatelessBean2 myBean2;      public void processObjects(List<Object> objs) {         // this method just processes the data; no need for a transaction         for(Object obj : objs) {             this.myBean2.process(obj);         }     } }  @Stateless public class MyStatelessBean2 implements MyStatelessLocal2, MyStatelessRemote2 {     @PersistenceContext(unitName='myPC')     private EntityManager mgr;      @TransationAttribute(TransactionAttributeType.REQUIRES_NEW)     public void process(Object obj) {         // do some work with obj that must be in the scope of a transaction          this.mgr.merge(obj);         // ...         this.mgr.merge(obj);         // ...         this.mgr.flush();     } } 

but I’m still curious if it’s possible to accomplish this in one class. It looks to me like the transaction manager only operates at the bean level, even when individual methods are given more specific annotations. So if I mark one method in a way to prevent the transaction from starting calling other methods within that same instance will also not create a transaction, no matter how they’re marked?

I’m using JBoss Application Server 4.2.1.GA, but non-specific answers are welcome / preferred.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:03:33+00:00Added an answer on May 11, 2026 at 7:03 am

    Another way to do it is actually having both methods on the same bean – and having an @EJB reference to itself! Something like that:

    // supposing processObjects defined on MyStatelessRemote1 and process defined on MyStatelessLocal1 @Stateless @TransationAttribute(TransactionAttributeType.NOT_SUPPORTED) public class MyStatelessBean1 implements MyStatelessLocal1, MyStatelessRemote1 {     @EJB     private MyStatelessLocal1 myBean2;      public void processObjects(List<Object> objs) {         // this method just processes the data; no need for a transaction         for(Object obj : objs) {             this.myBean2.process(obj);         }     }       @TransationAttribute(TransactionAttributeType.REQUIRES_NEW)     public void process(Object obj) {         // do some work with obj that must be in the scope of a transaction          this.mgr.merge(obj);         // ...         this.mgr.merge(obj);         // ...         this.mgr.flush();     } } 

    This way you actually ‘force’ the process() method to be accessed via the ejb stack of proxies, therefore taking the @TransactionAttribute in effect – and still keeping only one class. Phew!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Session scoped bean @SessionScoped public class UserData implements Serializable { private
This is my stateless bean: @Stateless public class Finder { @PersistenceContext(unitName = production) EntityManager
Here's my Bean class source @Stateless(mappedName=StringVal) public class NewSessionBean implements NewSessionRemote { String val
I'm trying to load bean runtime configuration. @Stateless public class MyBean implements MyLocal{ @Resource
I have a stateless session bean which needs access to a factory class. Is
I have a stateless bean with bean-managed transactions, and a method like this: @Stateless
We have some JavaEE5 stateless EJB bean that passes the injected EntityManager to its
I have a stateless session bean and a standalone-java-program acting as a client. The
We have a strange situation where we lose a Stateless SessionBean in a Bean
I want to be able to do something like this in a stateless Session

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.