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 941741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:09:45+00:00 2026-05-15T22:09:45+00:00

@Stateless @LocalBean public class MySLSB { @Resource SessionContext ctx; @PersistenceContext(unitName = myPU) EntityManager em;

  • 0
    @Stateless    @LocalBean
    public class MySLSB {

            @Resource
            SessionContext ctx;
            @PersistenceContext(unitName = "myPU")
            EntityManager em;

            public void T1() {
                em.persist(new MyEntity(1L)); //T1 created!
/* wrong call to plain java object               
 T2();
 */     
//corrected by lookup its business object first 
ctx.getBusinessObject(MySLSB.class).T2();   
     ctx.setRollbackOnly();
            }

            @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
            public void T2() {
                em.persist(new MyEntity(2L)); //T2 created!
            }
        }

The client calls T1(), at first T2 as a new Transaction should be committed,
but T1 will be rolled back.

Expected result:

T1: insert into myentity set id=1;

T2: insert into myentity set id=2;

T2: commit;

T1: rollback;

-> The row with id=2 is created in DB.

Actual result:

insert into myentity set id=1;

insert into myentity set id=2;

rollback;

-> Nothing is created in DB.

What’s the problem? Thanks a lot!

  • 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. Editorial Team
    Editorial Team
    2026-05-15T22:09:46+00:00Added an answer on May 15, 2026 at 10:09 pm

    @Solution

    The problem is solved. i made a naive mistake.

    The call to T2() should lookup its business object, direct call to T2() IS merely to its plain java object.

    i updated the code on the question above, making everything worked just as expected.

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

Sidebar

Related Questions

The following code works: @Stateless @LocalBean public class MyClass { @PersistenceContext(name = MyPU) EntityManager
For example, can I do the following @Stateless @LocalBean public class MyBean extends AbstractFacade<MyBeanEntity>
I have a no-interface ejb deployed in an ear (MyEar.ear) @Stateless @LocalBean public class
Suppose I have a stateless bean: @Stateless(name = fooBean) @LocalBean public class Foo {
Simple WebSevice @WebService @Stateless public class HistoryFormatterWebService implements IHistoryFormatterWebService { @EJB private IHistoryFormatter historyFormatter;
@Path(value = /user) @Stateless public class UserService { @Inject private UserManager manager; @Path(value =
I have a structure like this @Stateless public class CoreMainEJB implements CoreMainEJBRemote, CoreMainEJBLocal {
This is my SLSB: @Stateless(name = FinderEJB) @Path(/) public class Finder implements FinderLocal {
I have the following code: @Name(myService) @Scope(ScopeType.APPLICATION) @Stateless public class MyService { private Service
i have this in the server: class Person{...} and @Stateless public class HelloServiceBean implements

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.