5

来自 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]
}

然后调用delete()Airport 实例将删除所有关联的 Flight 对象(因为它们属于机场)。如果我要使用删除机场,executeUpdate我还能期望它删除航班吗?

谢谢

4

1 回答 1

4

它不是。这是一个简单的例子:

 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

有一个未解决的 Hibernate 问题要求能够在此处的查询中指定级联。

也备份在 Grails 邮件列表中。

于 2010-12-15T17:48:22.717 回答