5

From the Grails site: 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]
}

Then calling delete() on an instance of Airport will delete any associated Flight objects (since they belongTo airport). If I were to delete an Airport using executeUpdate can I still expect it to delete the Flights?

Thank you

Igor
  • 33,276
  • 14
  • 79
  • 112

1 Answers1

4

It does not. Here's a quick example:

 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'")

Yields (abbreviated):

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

There's an unresolved Hibernate issue requesting the ability to specify the cascade in the query here.

This is also backed up on the Grails mailing list here.

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
  • There are probably ways you can get around this by manually configuring hibernate (hibernate.cfg.xml), if you have to. – Rob Hruska Dec 15 '10 at 18:31