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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:02:20+00:00 2026-06-02T18:02:20+00:00

Is there any way to avoid having JPA to automatically persist objects? I need

  • 0

Is there any way to avoid having JPA to automatically persist objects?

I need to use a third party API and I have to pull/push from data from/to it. I’ve got a class responsible to interface the API and I have a method like this:

public User pullUser(int userId) {
    Map<String,String> userData = getUserDataFromApi(userId);
    return new UserJpa(userId, userData.get("name"));
}

Where the UserJpa class looks like:

@Entity
@Table
public class UserJpa implements User
{
    @Id
    @Column(name = "id", nullable = false)
    private int id;

    @Column(name = "name", nullable = false, length = 20)
    private String name;

    public UserJpa() {
    }

    public UserJpa(int id, String name) {
        this.id = id;
        this.name = name;
    }
}

When I call the method (e.g. pullUser(1)), the returned user is automatically stored in the database. I don’t want this to happen, is there a solution to avoid it? I know a solution could be to create a new class implementing User and return an instance of this class in the pullUser() method, is this a good practice?

Thank you.

  • 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-02T18:02:21+00:00Added an answer on June 2, 2026 at 6:02 pm

    Newly create instance of UserJpa is not persisted in pullUser. I assume also that there is not some odd implementation in getUserDataFromApi actually persisting something for same id.

    In your case entity manager knows nothing about new instance of UserJPA. Generally entities are persisted via merge/persist calls or as a result of cascaded merge/persist operation. Check for these elsewhere in code base.

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

Sidebar

Related Questions

Is there any way to avoid having unwanted fields generated into MVC views by
is there any way to avoid using tmp table? I am using a query
is there any way to avoid using tmp table? I am using a query
Is there any way I can avoid using array_flip to optimize performance. I am
Is there any way to have Json.net serialize an object directly to a NetworkStream?
Is there any way in Java to use a special delimiter at the start
Is there any way to implement isset() in a setter method? That is, have
Is there a way to avoid having multiple sets of drawables per resolution? I
Is there any way to change the BackColor of the border of a panel
Is there any way I can run class files (i.e. with main as the

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.