Igo*_*gor 5 grails groovy grails-orm belongs-to cascading-deletes
来自Grails网站:http://www.grails.org/doc/1.0.x/guide/5.%20Object%20Relational%20Mapping%20( GORM).html
class Airport {
String name
static hasMany = [flights:Flight]
}
class Flight {
String number
static belongsTo = [airport:Airport]
}
Run Code Online (Sandbox Code Playgroud)
然后调用delete()机场实例将删除任何关联的Flight对象(因为它们属于机场).如果我要删除机场,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'")
Run Code Online (Sandbox Code Playgroud)
产量(略):
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
Run Code Online (Sandbox Code Playgroud)
有一个未解决的 Hibernate 问题,要求能够在此处的查询中指定级联。
此处的Grails 邮件列表也对此进行了备份。
| 归档时间: |
|
| 查看次数: |
1018 次 |
| 最近记录: |