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

1 Answer 1

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.

1
  • There are probably ways you can get around this by manually configuring hibernate (hibernate.cfg.xml), if you have to.
    – Rob Hruska
    Dec 15, 2010 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.