在尝试使用 JPA 2.0 在一对多关系中插入新元素时,我收到一条恼人的错误消息。
public class Ordinateur implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "TAG")
private BigInteger tag;
@Size(max = 30)
@Column(name = "MACHINE")
private String machine;
@Size(max = 25)
@Column(name = "NOM_FABRIQUANT")
private String nomFabriquant;
@Column(name = "NUM_SERIE")
private BigInteger numSerie;
@Column(name = "ADRESSE_IP")
private BigInteger adresseIp;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Column(name = "NUM_SEQ")
private BigInteger numSeq;
@Size(max = 30)
@Column(name = "SYSTEME_EXPLOITATION")
private String systemeExploitation;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 30)
@Column(name = "IDORD")
private String idord;
@OneToMany(mappedBy = "idord")
private List<Systemeexploitation> systemeexploitationList;
@OneToMany(mappedBy = "idord")
private List<Intervention> interventionList;
@OneToMany(mappedBy = "idord")
private List<Inventaire> inventaireList;
public Ordinateur() {
} //...........
我的会话 bean:
public void ordCreer(Ordinateur ordinateur) {
ordinateurFacade.create(ordinateur);
}
托管豆:
public String enregistrerOrd() throws Exception{
manager.ordCreer(ordinateur);
return "OrdList";
}
这是错误:
ATTENTION: EJB5184:A system exception occurred during an invocation on EJB OrdinateurFacade, method: public void ejb.AbstractFacade.create(java.lang.Object)
ATTENTION: javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean
at com.sun.ejb.containers.BaseContainer.checkExceptionClientTx(BaseContainer.java:5071)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4906)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:89)
at $Proxy312.create(Unknown Source)
at ejb.__EJB31_Generated__OrdinateurFacade__Intf____Bean__.create(Unknown Source)
//...
Caused by: javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details.
//...
TTENTION: EJB5184:A system exception occurred during an invocation on EJB Manager, method: public void DAO.Manager.ordCreer(jpa.Ordinateur)
ATTENTION: javax.ejb.EJBTransactionRolledbackException
at com.sun.ejb.containers.BaseContainer.mapLocal3xException(BaseContainer.java:2314)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2096)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:89)
at $Proxy312.create(Unknown Source)
at ejb.__EJB31_Generated__OrdinateurFacade__Intf____Bean__.create(Unknown Source)
//................
Caused by: javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean
at com.sun.ejb.containers.BaseContainer.checkExceptionClientTx(BaseContainer.java:5071)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4906)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
... 80 more
Caused by: javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details.
at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.validateOnCallbackEvent(BeanValidationListener.java:90)
at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.prePersist(BeanValidationListener.java:62)
at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:698)
我试图删除 @NotNull 但什么也没发生 知道原因吗?