当不使用domain.delete()时,Grails Cascade是否会删除?
-
10-10-2019 - |
题
来自圣杯网站: http://www.grails.org/doc/1.0.x/guide/5.%20Object%20Relational%20Mapping%20Mapping%20(Gorm).html
class Airport {
String name
static hasMany = [flights:Flight]
}
class Flight {
String number
static belongsTo = [airport:Airport]
}
然后打电话 delete()
在机场的一个情况下,将删除任何关联的飞行对象(因为它们属于机场)。如果我要删除机场 executeUpdate
我还能期望它删除航班吗?
谢谢
解决方案
它不是。这是一个快速示例:
def a0 = new Airport(name: 'Dulles').save()
def f0 = new Flight(number: '1000', airport: a0).save()
assert 1 == Airport.count()
assert 1 == Flight.count()
Airport.executeUpdate("delete Airport a where a.name = 'Dulles'")
产量(缩写):
Caused by: java.sql.SQLException: Integrity constraint violation FKB4318470B2E8D1BA table: FLIGHT in statement [delete from airport where name='Dulles']
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
... 27 more
有一个未解决的冬眠问题,要求在查询中指定级联 这里.
这也可以在Grails邮件列表中备份 这里.
不隶属于 StackOverflow