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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:04:57+00:00 2026-05-31T22:04:57+00:00

When merging JPA entities using JpaTemplate in methods marked with @Async, the entity does

  • 0

When merging JPA entities using JpaTemplate in methods marked with @Async, the entity does not get an id. However, this works when merging it all in the same thread. (but taking way too long unfortunately).

For example:

  ...

  @Autowired
  private JpaTemplate jpaTemplate;

  @Async
  public Future<Foo> asyncSave(final Foo foo) {
    return new AsyncResult<Foo>(save(foo));
  }

  @Override
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public Foo save(final Foo foo) {
    final Foo savedFoo = jpaTemplate.merge(foo); 
    return savedFoo; // <== savedFoo.getId() returns null !
  }

  ...

Calling the method “asyncSave()” returns a Foo instance w/o id. In fact, I suspect the object returned is in the same state as before the merge. I’m seeing lots of SQL passing by on the console. The call to asyncSave() is coming from another repository object. And it really is a separate thread. So, what else can it be ?

Somebody ever had the same problem ?

  • 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-31T22:04:58+00:00Added an answer on May 31, 2026 at 10:04 pm

    Try to add @Transactional on method asyncSave.

    ...
    @Async
    @Transactional
    public Future<Foo> asyncSave(final Foo foo) {
      return new AsyncResult<Foo>(save(foo));
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When merging topic branch "B" into "A" using git merge , I get some
I am using JPA in a Glassfish Container. I have the following Modell (not
When merging two code branches in Team Foundation Server I get the following error:
When merging a couple of branches (using SVN 1.6.1) where a file has been
I've been reading up on branching/merging with Subversion 1.5 using the excellent and free
Merging in my Mercurial repository is not working like I expected. Several days ago
I am merging some png files to a uiimage and I followed this thread
I'm having trouble merging the two concepts of using a SplitViewController in my main
I've got a JPA entity Request, that owns a List of Answers (also JPA
I have this problem where I'm merging changes up into my integration branch but

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.