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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:07:19+00:00 2026-05-30T05:07:19+00:00

When I persist an object with a foreign key, I see in the logs

  • 0

When I persist an object with a foreign key, I see in the logs that eclipselink goes off and does a verification query, like this:
I also see that eclipselink finds this object and binds it. I don’t want it to do either of these things.

Basically I am trying to save object A, and A has a relationship with object B. When I go to insert a new A, all I have is the ID for B, not an instance of class B, and I am not interested in obtaining an instance of B in this case.

Something like this:

String b_id = "12345";
A a = new A();
B b = new B();
b.setId(b_id);
a.setB(b);


//begin tran
try {
    em.persist(a);
//commit
} catch (Exception e) {
    e.printStackTrace();
    //rollback
}

which causes this in the logs:

Execute query DoesExistQuery(referenceClass=B)
SELECT ID FROM B WHERE (ID = ?)
bind => [12345]

Now I want to insert A without Eclipselink going to verify if there exists a B with this Id, and I don’t want it to bind this B to the field of A which is an instance of B.

I don’t want Eclipselink adding this overhead to the insert, because the database is going to be doing this validation before the insert anyways, and I don’t need an actual instance of B in this case.

Any reply is appreciated, thanks!

  • 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-30T05:07:20+00:00Added an answer on May 30, 2026 at 5:07 am

    This is normally the role of the EntityManager.getReference() method: it creates and returns a proxy to the entity having the given class and ID, without hitting the database:

    A a = new A();
    B b = em.getReference(B.class, bId);
    a.setB(b);
    

    I have no experience with EclipseLink though, so I don’t know when exactly is this query executed.

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

Sidebar

Related Questions

I need to persist an object that is not marked with the serializable attribute.
I'd like to use object database to persist some classes created in IronPython. The
I have a Map, that I want to persist. The domain object is something
When I persist a question instance, the answer objects related to that question does
I am getting below error whilst trying to persist an object that has a
I have an application that has many different types of objects that each persist
I'm looking to persist and retrieve a large amount of key-value pair(s) type data
I have two tables: Transactions and TransactionAgents. TransactionAgents has a foreign key to Transactions
I have a mapped POJO which I need to persist. In that POJO I
I'm getting the following exception: Referential integrity constraint violation: FK779B6FDFD4D56C1: PUBLIC.LOG_TAG FOREIGN KEY(PEOPLE_ID) REFERENCES

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.