Hello,
I want to create a one to one mapping between the Entity Customer and OptIn. The OptIn Entity is optional. That is why the foreign key must be in OptIn. At deployment I get the following error because the mapping can not be found:
OneToOneSecondPass.java:135
Values: otherSide= optIn, mappedBy=customer
otherSideProperty = BinderHelper.findPropertyByName( otherSide, mappedBy );
java.lang.NullPointerException at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:135) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130) at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296) at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115) ...
What can I do to get a correct mapping?
@Entity
@Table(name = "KPS_OPT_IN", schema = "EB")
public class OptIn extends KmsEntity implements java.io.Serializable {
private static final long serialVersionUID = -8818445355079384264L;
private int id; /* kps_kunden_nr */
private Customer customer;
public OptIn() {
}
@Id
@Column(name = "KPS_KUNDEN_NR", unique = true, nullable = false)
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@OneToOne
@PrimaryKeyJoinColumn(name="KPS_KUNDEN_NR", referencedColumnName="KPS_KUNDEN_NR")
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
this.setId(customer.getId());
}
}
@Entity
@Table(name = "KPS_KUNDEN", schema = "EB")
public class Customer extends KmsEntity implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private int id;
private OptIn optIn;
public Customer() {
}
public Customer(int id) {
this.id = id;
}
@Id
@GeneratedValue(generator="seqkpskunde")
@SequenceGenerator(name="seqkpskunde",sequenceName="SEQ_KPS_KUNDE")
@Column(name = "KPS_KUNDEN_NR", unique = true, nullable = false)
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
if(optIn!=null){
optIn.setId(id);
}
}
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "customer")
public OptIn getOptIn() {
return optIn;
}
public void setOptIn(OptIn optIn) {
this.optIn = optIn;
}
}