我正在使用Play 2.0框架,我有三个类,Patient
,Visit
和Puberty
。 Patient
和Visit
具有ManyToOne关系,而Visit
和Puberty
具有一对一的关系(我知道,这在数据库设计中是不好的做法,但是Visit
有很多变量,我想把它们分开)。
public class Patient{
@Id
public Long id;
@OneToMany (mappedBy="patient", cascade=CascadeType.ALL)
public List<Visit> visits;
}
public class Visit{
@Id
public Long id;
@ManyToOne (cascade=CascadeType.ALL)
public Patient patient;
@OneToOne(mappedBy="visit", cascade={CascadeType.ALL})
public Puberty puberty;
}
public class Puberty{
@Id
public Long id;
@OneToOne
public Visit visit;
}
当我打电话给没有青春期访问的patient.delete()
时,它工作正常,但当访问青春期信息时,发生了以下错误:
play.api.Application $$ anon $ 1:执行异常[[PersistenceException:ERROR执行DML bindLog []错误[参照完整性约束违规:“FK_PUBERTY_DATA_VISIT_7:PUBLIC.PUBERTY_DATA FOREIGN KEY(VISIT_ID)参考PUBLIC.VISIT(ID) (100)“; SQL语句:\ n从访问中删除id =?和patient_id =? [23503-168]]]] at play.api.Application $ class.handleError(Application.scala:289)〜[play_2.10.jar:2.1.0] at play.api.DefaultApplication.handleError(Application.scala:383)[play_2.10.jar:2.1.0] at play.core.server.netty.PlayDefaultUpstreamHandler $$ anon $ 2 $$ anonfun $ handle $ 1.apply(PlayDefaultUpstreamHandler.scala:132)[play_2.10.jar:2.1.0] at play.core.server.netty.PlayDefaultUpstreamHandler $$ anon $ 2 $$ anonfun $ handle $ 1.apply(PlayDefaultUpstreamHandler.scala:128)[play_2.10.jar:2.1.0] at play.api.libs.concurrent.PlayPromise $$ anonfun $ extend1 $ 1.apply(Promise.scala:113)[play_2.10.jar:2.1.0] at play.api.libs.concurrent.PlayPromise $$ anonfun $ extend1 $ 1.apply(Promise.scala:113)[play_2.10.jar:2.1.0] javax.persistence.PersistenceException:ERROR执行DML bindLog []错误[参照完整性约束违规:“FK_PUBERTY_DATA_VISIT_7:PUBLIC.PUBERTY_DATA FOREIGN KEY(VISIT_ID)REFERENCES PUBLIC.VISIT(ID)(100)”; SQL语句:\ n从访问中删除id =?和patient_id =? [23503-168]] at com.avaje.ebeaninternal.server.persist.dml.DmlBeanPersister.execute(DmlBeanPersister.java:97)〜[avaje-ebeanorm-server.jar:na] at com.avaje.ebeaninternal.server.persist.dml.DmlBeanPersister.delete(DmlBeanPersister.java:48)〜[avaje-ebeanorm-server.jar:na] at com.avaje.ebeaninternal.server.persist.DefaultPersistExecute.executeDeleteBean(DefaultPersistExecute.java:109)〜[avaje-ebeanorm-server.jar:na] 在com.avaje.ebeaninternal.server.core.PersistRequestBean.executeNow(PersistRequestBean.java:489)〜[avaje-ebeanorm-server.jar:na] at com.avaje.ebeaninternal.server.core.PersistRequestBean.executeOrQueue(PersistRequestBean.java:511)~ [avaje-ebeanorm-server.jar:na] at com.avaje.ebeaninternal.server.persist.DefaultPersister.delete(DefaultPersister.java:635)〜[avaje-ebeanorm-server.jar:na] 引起:org.h2.jdbc.JdbcSQLException:参照完整性约束违规:“FK_PUBERTY_DATA_VISIT_7:PUBLIC.PUBERTY_DATA FOREIGN KEY(VISIT_ID)REFERENCES PUBLIC.VISIT(ID)(100)”; SQL语句: 从访问中删除id =?和patient_id =? [23503-168] 在org.h2.message.DbException.getJdbcSQLException(DbException.java:329)〜[h2.jar:1.3.168] at org.h2.message.DbException.get(DbException.java:169)〜[h2.jar:1.3.168] 在org.h2.message.DbException.get(DbException.java:146)〜[h2.jar:1.3.168] 在org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:414)〜[h2.jar:1.3.168] 在org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:431)〜[h2.jar:1.3.168] at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:307)〜[h2.jar:1.3.168]
我怀疑它与订单播放删除内容有关,它试图在青春期之前删除访问,有没有办法克服这个使用级联?或者我应该在访问中覆盖我的删除方法以自己指定它?
请帮忙......谢谢