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