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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:59:12+00:00 2026-05-14T00:59:12+00:00

I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A

  • 0

I have entity model like this (using EclipseLink and JPA 2.0):

@Entity
    class A {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      Long id;
      //equals, hashCode autogenerated by nb.

    }

And:

@Entity
        class B {
             @Id
              @GeneratedValue(strategy = GenerationType.AUTO)
              Long id;

             @ManyToOne
             A a;
              //equals, hashCode autogenerated by nb.
        }

I query all objects of type A, and all objects of type B, which have not null reference on B.a field. All objects are managed. For instance, lets take Collection<A> aObjects, Collection<B> bObjects.

Consider that aObjects.get(0).equals(bObjects.get(0).a), and a != null. How can I ensure that aObjects.get(0) == bObjects.get(0).a ?

I have equal / identical objects, but I would rather prefer the same object.

  • 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-14T00:59:12+00:00Added an answer on May 14, 2026 at 12:59 am

    JPA doesn’t work that way. The entity instances that you get back from the JPA API are “hydrated” containers representing the persistent data. The java objects themselves are not special, they’re just transient data holders.

    From that perspective, object identity is not important, object equality is.

    If your application requires object identity in this fashion, you’re going to be fighting a losing battle, since JPA is just not designed to bend in that direction.

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

Sidebar

Related Questions

I am using Hibernate with spring. I have a model-class like this. @Entity @Table(name
I'm using app engine datastore so I have entity like this. @PersistenceCapable public class
I have a view model like this: public class EditVM { public Media.Domain.Entities.Movie Movie
My django model looks like this: class Entity(models.Model): name = models.CharField(max_length=40) examples = models.ManyToManyField(Example,
Let's say I have a Student entity like this implemented using the Play Framework's
I'm working with a small model in Entity Framework 4.0. I'd like to have
I have an entity model where the base class in an inheritance structure has
I am trying to design an entity model using JPA2.0 via hibernate. I have
I have 2 projects - a class library containing an EDM Entity Framework model
I have a edmx file created using the entity entity framework model. Whenever I

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.