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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:37:50+00:00 2026-05-18T05:37:50+00:00

The following (simplified version of our) code passes our JUnit tests under Hibernate, but

  • 0

The following (simplified version of our) code passes our JUnit tests under Hibernate, but not under EclipseLink. What is needed to make this work under EclipseLink?

public static void store(EntityManager em, String a, String b) {
    Entry entry=new Entry();
    entry.setFirst(a);
    entry.setLast(b);
    em.persist(entry);
    em.persist(new SubEntry(entry.getId(), a, b));
}

It fails because entry.getId() is returning 0 when using EclipseLink. What is the appropriate way to retrieve the unique identifier of an object that has just been stored?

It appears obvious that the above code doesn’t make sense, as doing an entry.getId() before the transaction has been committed probably does not make sense, however hibernate allowed it.

  • 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-18T05:37:51+00:00Added an answer on May 18, 2026 at 5:37 am

    There are a few things going on here. Unless you provide some of the code for your entity classes, we can’t know what kind of strategy you are using for primary key generation. Let me assume that you’re using a strategy that allows the database to generate a primary key for your Entry class, such as a sequence or auto-number column. Let me further assume that you’re calling this method inside an active transaction. If you insert a call to em.flush() right after your call to em.persist(entry) then I think this will work, given the assumptions that I stated above.

    The unknown that I see is whether or not entry is a reference to a managed entity when you make the second call to em.persist() and whether or not it has been assigned an id (primary key) value yet.

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

Sidebar

Related Questions

The following code is a simplified version of what I use for event dispatching.
I have a code a following (simplified version): #define MESSAGE_SIZE_MAX 1024 #defined MESSAGE_COUNT_MAX 20
Below, is a simplified version of my App , the following code works as
I have the following function in my code. Here's a simplified version: $.ajax({ url:
Consider the following simplified version of my code. I have a template class A
The following code is the simplified version of my problem: public partial class Form1
The following code snippet is a simplified version of my issue. Basically I'm trying
Please see the following example which is a very simplified version of my code:
I have the following C++ code (simplified version): class Shape { bool isCircle =
I am debugging some code and have encountered the following SQL query (simplified version):

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.