Question

À partir du site 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]
}

Ensuite, appelant delete() sur une instance de l'aéroport supprimera tous les objets vol associés (car ils belongTo aéroport). Si je devais supprimer un aéroport en utilisant executeUpdate puis-je attendre encore pour supprimer les vols?

Merci

Était-ce utile?

La solution

Il ne fonctionne pas. Voici un exemple rapide:

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

Les rendements (en abrégé):

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

Il y a un problème non résolu Hibernate demandant la possibilité de spécifier la cascade dans la requête ici .

Ceci est également sauvegardé sur la liste de diffusion Grails ici .

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top