Greetings! Could someone help me with this, please?
I have a very simple unidirectional many-to-one (an Member knows its Freelancetype). The type information should be optional e.g. when loading Member, Freelancetype should be either null (no PK-FK match in DB), or fully loaded. Instead when PK-FK match fails, I get non-null member. getFreelancetype(), where Freelancetype returned has null fields (including freelancetypeid). Looks like Hibernate decides to instantiate a new Freelancetype for a Member if it can't load one from DB.
How to avoid it?
Hibernate version:
3.2.0.cr2
Mapping documents:
Code:
@Entity
public class Member
{
//...
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumn(name = "freelancetypeid", unique = false, nullable = true, insertable = true, updatable = true)
public Freelancetype getFreelancetype() {
return this.freelancetype;
}
//...
}
@Etity
public class Freelancetype implements java.io.Serializable {
private String freelancetypeid;
private String freelancetypedesc;
//...
@Id
@Column(name = "freelancetypeid", unique = true, nullable = false, insertable = true, updatable = true, length = 2)
public String getFreelancetypeid() {
return this.freelancetypeid;
}
}
Name and version of the database you are using:
PostgreSQL 8.1