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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:57:36+00:00 2026-06-16T14:57:36+00:00

I have a question regarding Hibernate. I have two objects with a Many-to-One relationship:

  • 0

I have a question regarding Hibernate.

I have two objects with a Many-to-One relationship:

Eg:
Object 1:

 public class Person {

 @Basic
 @Column(length = 50)
 protected String name;

 @NotFound(action=NotFoundAction.IGNORE)
 @ManyToOne(fetch = FetchType.EAGER)
 @JoinColumn(name = "groupCode", referencedColumnName = "code", updatable=false)
 protected Group group;

 ...all the getters and setters...
 }

Object 2:

 public class Group {
  @Id
  @Basic
  @Column(length = 3, nullable = false)
  protected String code;

  @Basic
  @Column(length = 30, nullable = false)
  protected String groupName;

   @Basic
   @Column(precision = 15, scale = 0)
   protected long exampleFieldId;

   ...rest of code....
  }

I have tried to make this example as simple as possible. My issue is that the associated object (Group) on Person can be null. Currently, Hibernate loads up an instance of Group when I load up a particular Person and throws an exception because it cannot set exampleFieldId to be null (as it is a primitive type).

I can stop this error by changing long to be Long however, I would have thought that the Group object on Person should be null and thus no Group object loaded in the first place?

Does anyone know if Hibernate loads the associated object regardless of it being allowed to be null, or have I missed some important annotation?

Thanks

  • 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-16T14:57:37+00:00Added an answer on June 16, 2026 at 2:57 pm

    As mentioned by Firo:

    have you disabled lazy loading and set fetchmnode to join because
    NHibernate has to fetch them to decide if it should nullify it or not
    and it can not decide that only with an id

    This seems to be the same issue you are experiencing even though it is in NHibernate. Worth checking though!

    Why does Hibernate attempt to load "not-found=ignore" associations?

    Edit: It could be that you’re missing @Fetch(FetchMode.JOIN).

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

Sidebar

Related Questions

simple question regarding HQL(Hibernate query language) so i have user class , that can
I have question regarding the SQLAlchemy. How can I add into my mapped class
i have a question regarding the AsyncTask class in android, and why it is
I have a question regarding the proper way to modify a php DateTime object.
I am learning hibernate and have a question regarding the design of my POJO
I have question regarding macros. How could I cast through macro a template class
I have question regarding the CreateWindowEx function. I have 2 windows, a main one
I have a question regarding inheritance with function objects. I guess this must have
I have one question regarding unwanted extra jar files . First I had planned
I have question regarding the use of function parameters. In the past I have

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.