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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:28:48+00:00 2026-06-11T19:28:48+00:00

Trying to persist an entity which contains a member variable that is a reference

  • 0

Trying to persist an entity which contains a member variable that is a reference to some other entity which is not under the current persistence context will not be possible, when this happens one needs to fetch the required entity and set it in the original entity in order to respect the relationship and be allowed to persist it.

When I need to accomplish this I usually make use of the EntityManager’s find method, but that will hit the database and fetch the entire entity along with it’s relationships that may not be annotated for lazy loading. I was happy to find out about getReference, which suposedly won’t hit the database but return a proxy representation where only the primary key is available and that is really all that is required for this type of situation.

Unfortunately after some debugging I find myself being able to view all the information about the getReference‘d entity and not just the primary key when I “inspect” it via Eclipse debug mode.

Am I missing something? Am I being deceived by the debug mode? Could it be fetching the information like a getter method would when used on the proxy reference?

Thanks in advance

  • 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-11T19:28:50+00:00Added an answer on June 11, 2026 at 7:28 pm

    Whe you inspect it using the Eclipse debugger, the debugger initializes the proxy. Just turn on SQL logging, execute the em.getReference() method, and verify that no select statement has been executed by your JPA engine.

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

Sidebar

Related Questions

I am trying to persist an Entity with a @Lob annotated String field. The
I am trying to persist member variables by saving them in the ViewState (only
I am trying to persist a Template object in the app's database. It's not
I have a rather deep hierarchy of objects that I'm trying to persist with
I'm trying to persist an object into the database using Cayenne Entity Manager. And
I'm trying to persist a very simple class using Hibernate. I'm not using Spring,
I'm trying to persist roughly 28,000 rows in a single entity e.g. EMPLOYEE Basically,
I'm using JPA2 and Hibernate implementation. I'm trying to persist a User object, which
I have a WPF application in which I'm trying to use Entity Framework 4.1
I'm trying to intercept the method persist and update of javax.persistence.EntityManager in a Seam

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.