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

  • Home
  • SEARCH
  • 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 6217901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:30:23+00:00 2026-05-24T07:30:23+00:00

I am using an embedded id: @Embeddable public class EntityId { private long id;

  • 0

I am using an embedded id:

@Embeddable
public class EntityId {
    private long id;
}

And I have the following tables:

@Entity
public class Master {
    @EmbeddedId private EntityId id;

    @OneToMany(mappedBy = "master")
    Set<Config> configs;
}

@Entity
public class SlaveLeft {
    private @EmbeddedId EntityId id;
}

@Entity
public class SlaveRight {
    private @EmbeddedId EntityId id;
}

@Entity
public class Config {

    @EmbeddedId private EntityId id;

    @ManyToOne
    @JoinColumn(name = "MASTER_ID", referencedColumnName = "id")
    private Master master;
    @ManyToOne
    @JoinColumn(name = "LEFT_ID", referencedColumnName = "id")
    private SlaveLeft slaveLeft;
    @ManyToOne
    @JoinColumn(name = "RIGHT_ID", referencedColumnName = "id")
    private SlaveRight slaveRight;
}

I then populate the database:

    final EntityManager em = injector.getInstance(EntityManager.class);
    em.getTransaction().begin();
    Master master = new Master(EntityId.next());
    SlaveLeft slaveLeft = new SlaveLeft(EntityId.next());
    SlaveRight slaveRight = new SlaveRight(EntityId.next());
    Config config = new Config(EntityId.next(), master, slaveLeft, slaveRight);

    em.persist(master);
    em.persist(slaveLeft);
    em.persist(slaveRight);
    em.persist(config);
    em.getTransaction().commit();

    final Master master1 = em.find(Master.class, master.getId());
    System.out.println(master1.getConfigs());

The problem is that the master1.getConfigs() returns empty.

What am I missing to get a working relation?

  • 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-24T07:30:24+00:00Added an answer on May 24, 2026 at 7:30 am

    If you use another entity maneger to find your master, its configs collection will probably be populated. But here, the entity manager returns the master from its cache, and since you didn’t put the config into the master’s set of configs, it isn’t there.

    When using a bidirectional relationship, you are responsible for the maintenance of both sides of the relationship. The ORM only uses the owning side (the one without the mappedBy attribute) to decide if the relationship exists or not, but the coherence of the object graph is your responsibility.

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

Sidebar

Related Questions

I have an install of django on apache using embedded wsgi. I DON'T have
We have a setup where we are using an embedded HSQLDB for backing Hibernate/JPA
I have some Flash swfs that are embedded using swfobject and I pass them
I am using an embedded RISC processor. There is one basic thing I have
I have a simple Java web application using HSQLDB embedded database. The application is
I want to use criteria to make the following query. I have an Entity
I'm using embedded SQL with Java. I have a simple table where I want
I have a specific problem with an unit test using embedded OpenEJB container. I
I have a problem. I'm learning JPA. I'm using embedded OpenEJB container in unit
I am using embedded-linux for device which has Arch ARMv5 Speed 266MHZ, vfpu and

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.