Je souhaite créer un mappage un à un entre Entity Customer et OptIn. L'entité OptIn est facultative. C'est pourquoi la clé étrangère doit être dans OptIn. Au déploiement, je reçois l'erreur suivante car le mappage ne peut pas être trouvé:OneToOne Mapping avec hibernate/JBoss/Seam
OneToOneSecondPass.java:135
Valeurs: = Otherside optin, mappedBy = client
otherSideProperty = BinderHelper.findPropertyByName (Otherside , mappéBy);
java.lang.NullPointerException à org.hibernate.cfg.OneToOneSecondPass.doSecondPass (OneToOneSecondPass.java:135) à org.hibernate.cfg.Configuration.secondPassCompile (Configuration.java:1130) à org.hibernate .cfg.AnnotationConfiguration.secondPassCompile (AnnotationConfiguration.java:296) à org.hibernate.cfg.Configuration.buildMappings (Configuration.java:1115) ...
Que puis-je faire pour obtenir une cartographie correcte?
@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;
}
}
Merci beaucoup pour l'instant. Je vais essayer ça demain. Voulez-vous dire OptIn est seulement facultatif si la clé/Id n'est dans aucune des deux tables? –
Le client est le propriétaire de cette relation. Donc, si vous avez un client avec pk = 314 et OptIn avec pk = 314, la relation sera là. Si vous n'avez pas d'OptIn avec pk = 314, la propriété 'Customer.optIn' sera NULL. – ChssPly76
Malheureusement, je ne pourrais pas le faire fonctionner si l'id pour la jointure est des références d'OptIn (mappedBy = "client"), seulement si j'utilise l'id dans le client. J'utilise hibernate 3.2.4sp1 et les annotations 3.3.0GA. La solution avec l'utilisation de l'id du client est satisfaisante pour moi. –