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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:57:22+00:00 2026-06-13T01:57:22+00:00

Please see my following code snippet. @Transactional public void saveMembersService(List<Member> list1, List<Member> list2) {

  • 0

Please see my following code snippet.

@Transactional
public void saveMembersService(List<Member> list1, List<Member> list2)
{
    saveMembersDAO(list1); // does not perform commit. Why?
    saveMembersDAO(list2); // does not perform commit. Why?
} // does perform commit only here!

@PersistenceContext
private EntityManager em;

@Transactional
public void saveMembersDAO(List<Member> members)
    throws HibernateException
{
    Iterator<Member> it = members.iterator();
    while (it.hasNext())
    {
        Member wsBean = it.next();
        em.persist(wsBean); // overall commit will be made after method exit
    }
}

I use MySQL as DB. I watch MySql logs after above method execution. But I can see only single commit after saveMembersService method execution. I expect to see two commits for each transactional method invocation. Where am I wrong ?

UPDATE 1: Sorry, I have forgot to add @Transactional to my service method. It fixed now

UPDATE 2: I’ve checked with Propagation.REQUIRES_NEW attribute for DAO – result is the same (with and with out @Transactional at service method)

  • 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-06-13T01:57:25+00:00Added an answer on June 13, 2026 at 1:57 am

    When @Transactional is used, Spring creates a proxy around your class and methods called internally does not pass in the proxy.

    You have to do this instead. You can clean it by creating your TransactionTemplate in your Spring context.

    @Autowired
    private PlatformTransactionManager transactionManager;
    
    public void saveMembersDAO(List<Member> members)
        throws HibernateException
    {
        TransactionDefinition txDef = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        TransactionTemplate txTemplate = new TransactionTemplate(transactionManager, trDef)
    
        txTemplate.execute(new TransactionCallbackWithoutResult() {
    
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                Iterator<Member> it = members.iterator();
                while (it.hasNext())
                {
                    Member wsBean = it.next();
                    em.persist(wsBean);
                }
            }
        });
    }
    

    If you are using AspectJ and you want to have 2 commits. You must use a @Transactional(propagation = Propagation.REQUIRES_NEW) on saveMembersDAO

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

Sidebar

Related Questions

Please see the following code: public void UpdateChildPagesReWrittenUrl(int parentPageId) { var childPageList = db.PcPages.Where(m
Please see the following code: List list = Collections.synchronizedList(new ArrayList()); // ... synchronized (list)
Please explain why the following code snippet fails to compile: public class ScjpTest{ static
Please see the following code to understand my question better. class compareByValue { public:
Please see the following code and explain the output behavior. public class MyFinalTest {
Help me understand the following code snippet: (foo.h) class Foo { public: typedef void
How do we update a textbox on ticking checkboxes? Please see the following code,
Please see following methods. public static ProductsCollection GetDummyData(int? customerId, int? supplierId) { try {
Can someone please explain me the following code snippet? value struct ValueStruct { int
Please see the following code: def good(): foo[0] = 9 # why this foo

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.