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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:38:21+00:00 2026-06-09T04:38:21+00:00

Suppose I have 2 entities, EntityA and EntityB. EntityB is @OneToOne related to EntityA:

  • 0

Suppose I have 2 entities, EntityA and EntityB.
EntityB is @OneToOne related to EntityA:

@Entity
public class EntityB {
    @OneToOne(fetch = FetchType.LAZY)
    private EntityA entA;

    // other stuff
}

When I load EntityB from DB, the corresponding EntityA (say entA1) is lazy loaded.
After that I load EntityA list by

   List result = entityManager.createQuery("select A from EntityA A")
                  .setFirstResult(start).setMaxResults(end).getResultList();

The result list contains both previously lazy loaded and proxied EntityA and normal materialized EntityAs such like:

EntityA
EntityA_$$_javassist_nnn   <--- entA1 which is loaded lazily earlier
EntityA
...

So my questions:
1) Is this an expected behavior? Where can I find apidoc info about that?
2) Can I entirely load proxied entities only or entirely load eagerly all of them? Not mixed.

  • 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-09T04:38:24+00:00Added an answer on June 9, 2026 at 4:38 am

    Yes, it’s expected behavior. Hibernate does everything it can to have one and only one instance of an entity in the session. Since it already has a proxy to EntityA, stored in the session when you loaded EntityB, a subsequent query returning the same EntityA instance effectively return the same instance: the proxy already stored in the session.

    You shouldn’t care much about the fact that the list contains proxies. Calling any method on the proxy (except getClass()) will return the same thing as calling it on the unproxied entity.

    AFAIK, that’s what allows having collections of entities behaving correctly with attached objects, although the objects don’t even have an equals() method.

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

Sidebar

Related Questions

Suppose I have the following 2 entities: @Entity public class Person implements Serializable {
Suppose I have the following entities: @Entity @Table(name = A) public class A implements
Suppose we have the following entities: public class plaserv { public virtual int id
Technology: Hibernate 3.0 Suppose i have Entity class Company @Entity @Table(name=tbl_companies) public class Company
Suppose we have typical repository public class Repository:IRepository<Entity> { public Entity GetById(int id) {
Suppose I have a simple model, such as Record: @Model public class Record {
Suppose there are two entities EntityA and EntityB. Two tables are defined for both
Suppose i have a one to many relationship between two model entities Entity One
Suppose I have core data entities A and B, where B points to A
Suppose I have a static method of my class that returns an object of

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.