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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:07:03+00:00 2026-06-12T09:07:03+00:00

We have an entities like this: public User { @OneToMany(fetch = FetchType.EAGER, cascade =

  • 0

We have an entities like this:

public User {
    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name = "user_id", insertable = true, updatable = true)
    @ElementDependent
    private List<Item_x> item_x_list = new ArrayList<Item_x>();
}

public Item_x {
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", insertable = true, updatable = true)
    @Element(name = "user_id", required = false)
    private Users user;
}

Whenever I add/remove items to User.item_x_list and then persist the User entity using em.merge(User.INSTANCE) the Item_x.user property is NULL.

I am loading the Item_x.user property with a JOIN FETCH query to make sure the attribute is loaded (when I need it). However: the Item_x.user property is NULL even with FETCH JOIN if you have performed a merge on the User Entity.

I tried to workaround by refreshing the Item_x.INSTANCE
but when I call:

em.refresh(Item_x.Instance);

=> user is null.

Looking in the database I of course can see that the user is NOT null in the Item_x.

How can I force OpenJPA to correctly load the user in Item_x ?
Why is OpenJPA not filling correctly the Item_x.user property / ignores the JOIN FETCH statement?

  • 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-12T09:07:04+00:00Added an answer on June 12, 2026 at 9:07 am

    It looks like the problem is that you’ve created two uni-directional relationships instead of a bi-directional relationship. One of your classes needs to define a mappedBy relation to the other class, which defines the other class as the “owner” of the relationship. For example, you can change your example above to define Item_x as the owner as follows:

    public User {
        @OneToMany(targetEntity = Item_x.class, mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
        @ElementDependent
        private List<Item_x> item_x_list = new ArrayList<Item_x>();
    }
    
    public Item_x {
        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "user_id", insertable = true, updatable = true)
        @Element(name = "user_id", required = false)
        private Users user;
    }
    

    More information is available in the OpenJPA documentation, but they’re missing examples which would make it more clear.

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

Sidebar

Related Questions

I have two entities like this: public class Service { public virtual int ServiceId
I have code like this: public bool Set(IEnumerable<WhiteForest.Common.Entities.Projections.RequestProjection> requests) { var documentSession = _documentStore.OpenSession();
I have a collection of entities with an any-association, like this: public class CreatedLog
I have some Entities that look like this: @Entity public abstract class AbstractEntity{ @Id
I have a model that looks like this: public interface IEntity { int Id
This is how my data model for USER looks like public class User {
I have, let's say, this simple class: public class User { [Required(AllowEmptyStrings = false,
I have an entity like this: public class Employment { public virtual Company Company
I have two simplest of Entities, similar to: public class User { int id;
I have 2 entities: public class User { public int userId { get; set;

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.