use*_*580 5 model-view-controller spring jpa
尝试使用JPA 2.0,SpringMvc 3.0在多对多关系中插入新元素时,我遇到了一条恼人的错误消息.
我有一张国家的桌子和另一张有人的桌子.一个人可以链接到许多州,一个州可以链接到许多人.在这种特殊情况下,我有一个listOfStates,然后是一个人,我想在我的多对多关系中插入这些元素.
ManyToMany关系(表STATE)
//bi-directional many-to-many association to Appointment
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(
name="PERSON_STATE"
, joinColumns={
@JoinColumn(name="PERSON_ID", nullable=false)
}
, inverseJoinColumns={
@JoinColumn(name="CODE_STATE", nullable=false)
}
)
Run Code Online (Sandbox Code Playgroud)
DAO Code我正从我的控制器那里打电话
try{
getEntityManager().getTransaction().begin();
getEntityManager().persist(myPerson);
IStateDAO stateDAO = new StateDAO();
for (int i=0; i<listOfStates.length; i++){
State myState = stateDAO.findState(listOfStates[i]);
if (myState != null){
myState.getPersons().add(myPerson);
getEntityManager().persist(myState);
}
}
getEntityManager().getTransaction().commit();
getEntityManager().close();
} catch (RuntimeException re) {
getEntityManager().close();
throw re;
}
Run Code Online (Sandbox Code Playgroud)
有趣的是,当我没有从网页插入数据时,这段代码工作正常.我在这里做错了什么?我已经在DB中有一些人和状态.
完整堆栈错误消息:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'preUpdate'. Please refer to embedded ConstraintViolations for details.
javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'preUpdate'. Please refer to embedded ConstraintViolations for details.
Run Code Online (Sandbox Code Playgroud)
任何指针都会非常感激.在此先感谢大家.
哇!得到它了!我不得不将persistence.xml中的验证模式从Auto更改为NONE,这基本上告诉应用程序根本不使用bean验证.错误消息消失了,我的DAO运行良好.
归档时间: |
|
查看次数: |
14095 次 |
最近记录: |