title: Hibernate doesn't get the full @ManyToOne object information needed after executing update
body: <p>I have a scenario when I need to update a relation a detail table &quot;USER_PROFILE&quot; in this case and update it's relation column reference to &quot;NATIONALITY&quot; parent table (just a change for NATIONALITY_ID column in USER_PROFILE, and NATIONALITY table is just a predefined lookup and won't change).</p>
  <p>So, my code sample is as follow:-</p>
  <pre><code>@Entity
  @Table(name = &quot;USER_PROFILE&quot;, schema = &quot;OQ_IDEATE&quot;)
  public class UserProfile {
  
      private Long userProfileId;
      private Nationality nationalityByNationalityId;
      private List&lt;UserSkills&gt; userSkillsByUserProfileId;
  
      @Id
      @Column(name = &quot;USER_PROFILE_ID&quot;, nullable = false)
      public Long getUserProfileId() {
          return userProfileId;
      }
  
      public void setUserProfileId(Long userProfileId) {
          this.userProfileId = userProfileId;
      }
  
      @ManyToOne
      @JoinColumn(name = &quot;NATIONALITY_ID&quot;, referencedColumnName = &quot;NATIONALITY_ID&quot;)
      public Nationality getNationalityByNationalityId() {
          return nationalityByNationalityId;
      }
  
      public void setNationalityByNationalityId(Nationality nationalityByNationalityId) {
          this.nationalityByNationalityId = nationalityByNationalityId;
      }
  
      @OneToMany(mappedBy = &quot;userProfileByUserId&quot;, cascade = CascadeType.ALL)
      public List&lt;UserSkills&gt; getUserSkillsByUserProfileId() {
          return userSkillsByUserProfileId;
      }
  
      public void setUserSkillsByUserProfileId(List&lt;UserSkills&gt; userSkillsByUserProfileId) {
          this.userSkillsByUserProfileId = userSkillsByUserProfileId;
      }
  }
  
  </code></pre>
  <pre><code>@Entity
  public class Nationality {
      private Long nationalityId;
      private String nationalityNameEn;
  
      public Nationality() {
      }
  
      public Nationality(Long nationalityId) {
          this.nationalityId = nationalityId;
      }
  
      @Id
      @Column(name = &quot;NATIONALITY_ID&quot;, nullable = false)
      public Long getNationalityId() {
          return nationalityId;
      }
  
      public void setNationalityId(Long nationalityId) {
          this.nationalityId = nationalityId;
      }
  
      @Basic
      @Column(name = &quot;NATIONALITY_EN&quot;, nullable = false, length = 200)
      public String getNationalityNameEn() {
          return nationalityNameEn;
      }
  
      public void setNationalityNameEn(String nationalityNameEn) {
          this.nationalityNameEn = nationalityNameEn;
      }
  
  }
  </code></pre>
  <pre><code>@Entity
  @Table(name = &quot;USER_SKILLS&quot;, schema = &quot;OQ_IDEATE&quot;)
  @IdClass(UserSkillsPK.class)
  public class UserSkills {
      private Long userId;
      private Long skillId;
      private UserProfile userProfileByUserId;
      private Skill skillBySkillId;
  
      public UserSkills() {
      }
  
      public UserSkills(UserProfile userProfile, Skill skill){
          this.userProfileByUserId = userProfile;
          this.skillBySkillId = skill;
          this.userId = userProfile.getUserProfileId();
          this.skillId = skill.getSkillId();
      }
  
      @Id
      @Column(name = &quot;USER_ID&quot;, nullable = false)
      public Long getUserId() {
          return userId;
      }
  
      public void setUserId(Long userId) {
          this.userId = userId;
      }
  
      @Id
      @Column(name = &quot;SKILL_ID&quot;, nullable = false)
      public Long getSkillId() {
          return skillId;
      }
  
      public void setSkillId(Long skillId) {
          this.skillId = skillId;
      }
  
      @MapsId(&quot;userId&quot;)
      @ManyToOne
      @JoinColumn(name = &quot;USER_ID&quot;, referencedColumnName = &quot;USER_PROFILE_ID&quot;, nullable = false)
      public UserProfile getUserProfileByUserId() {
          return userProfileByUserId;
      }
  
      public void setUserProfileByUserId(UserProfile userProfileByUserId) {
          this.userProfileByUserId = userProfileByUserId;
      }
  
      @MapsId(&quot;skillId&quot;)
      @ManyToOne
      @JoinColumn(name = &quot;SKILL_ID&quot;, referencedColumnName = &quot;SKILL_ID&quot;, nullable = false)
      public Skill getSkillBySkillId() {
          return skillBySkillId;
      }
  
      public void setSkillBySkillId(Skill skillBySkillId) {
          this.skillBySkillId = skillBySkillId;
      }
  }
  </code></pre>
  <p>And my spring data jpa that updates the entity is doing it's job by updating USER_PROFILE table values in DB, but I need to get the updated NATIONALITY_EN mapped value (as I changed reference column ID from 248 to 249) , I have to re-execute another SELECT statement to get the corresponding NATIONALITY_EN value.
  Even it's not the case for my @OneToMany mapping for List in UserProfile entity, I got the updated information without the need to re-select from the DB.</p>
  <pre><code>    @OneToMany(mappedBy = &quot;userProfileByUserId&quot;, cascade = CascadeType.ALL)
      public List&lt;UserSkills&gt; getUserSkillsByUserProfileId() {
          return userSkillsByUserProfileId;
      }
  </code></pre>
  <p>And here is the code that responsible for updates</p>
  <pre><code>     dbUserProfile.setUserSkillsByUserProfileId(userProfileDataPOJO.getUserSkills()
                  .stream()
                  .map(skill -&gt; new UserSkills(dbUserProfile, new Skill(skill.getSkillId())))
                  .collect(Collectors.toList()));
       dbUserProfile.setBusinessUnitByBusinessUnitId(new BusinessUnit(userProfileDataPOJO.getBusinessUnit().getBusUntId()));
       dbUserProfile.setNationalityByNationalityId(new Nationality(userProfileDataPOJO.getNationality().getNationalityId()));
       dbUserProfile = userProfileDao.save(dbUserProfile);
  
       // after updating and getting the updated UserProfile object from the DB  
       dbUserProfile.getNationalityByNationalityId().getNationalityNameEn();   \\ this is always null ..
       dbUserProfile.getUserSkillsByUserProfileId();   \\ this always return the full needed object
  </code></pre>
  <p>What I am asking here, is there any @annotation that will make Nationality object act the same as userSkills object? because I don't want to make another select call to the DB to load the needed value.</p>
  <p>Thanks in advance.</p>