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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:46:25+00:00 2026-06-03T03:46:25+00:00

I am attempting to update an existing record using JPA. The following link seems

  • 0

I am attempting to update an existing record using JPA. The following link seems to suggest that the only way to update a record would be to write the update query for it
enter link description here

Which is fine. But again, I am wondering why am I pulling this out of stored proc to use all f the magic of open JPA?
I thought that If I had an instance of a JPA object that if I tried to persist to the database using a call similar to this

emf.persist(launchRet)

the JPA framework would check to see if the record allready exists, if so, it would then proceed to make the changes to that record, if not, it would just add a new record. Which would be really cool. Instead, I am going to have to end up writing all that logic myself in an update query. Which is fine, But why can’t I just use a stored proc and just pass it all the necessary values?

UPDATE: CODE EXPLAINING WHAT MY LAST COMMENT IS ALL ABOUT

    try{
        launchRet = emf.find(QuickLaunch.class, launch.getQuickLaunchId());
        if(launchRet==null){                
            emf.getTransaction().begin();
            emf.persist(launchRet);
            emf.getTransaction().commit();
        }
        else{
            emf.refresh(launchRet);
        }
    }

The variable launch is passed into the method…

public QuickLaunch UpdateQuickLaunchComponent(QuickLaunch launch) 

Would I simple just set the found launch launchRet equal to the launch that was passed in?

  • 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-03T03:46:25+00:00Added an answer on June 3, 2026 at 3:46 am

    Read the link that you posted:

    You can modify an entity instance in one the following ways:

    • Using an Updating Query
    • Using the Entity’s Public API
      […]

    The way used in 99% of the cases is the second way:

    Foo someExistingFoo = em.find(Foo.class, someExistingFooId);
    someExistingFoo.setSomeValue(theNewValue);
    // no need to call any persist method: the EM will flush the new state 
    // of the entity to the database when needed
    

    Of course, the entity can also be loaded via a query, or by navigating through the graph of entities.

    If you have a detached entity, and you want to persist its state to the database, use the EntityManager.merge() method. It finds the entity with the same ID as the detached one passed as argument, copies the state from the detached entity to the attached one, and returns the attached one:

    Foo attachedModifiedFoo = em.merge(detachedFoo);
    

    If the detached entity isn’t persistent (i.e. doesn’t have any ID), then it is created and made persistent.

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

Sidebar

Related Questions

The example I'm hitting is that I'm attempting to update a record in a
I am getting an error msg when attempting to update a record from asp.net
I'm attempting to update my database table with the following code: public void onUpgrade(SQLiteDatabase
I am attempting to update to Hibernate 4 and I am getting that org.hibernate.annotations.Entity
I'm attempting to update my existing rails app (3.0.3) to 3.1.0.beta1. I've install the
I am attempting to update a page using Struts2 ( using jOWL to display
I am troubleshooting code that is attempting to update a disconnected entity that has
I'm attempting to connect to an existing Comet-style long-poll service using an AIR app.
I'm attempting to update a column with a string that contains a reserved word.
I am attempting to update my date_process field using php. The mysql field is

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.