A と B の 2 つのドメイン クラスがあります。A には複合キーがあります。その一部は B を指しています。そのフィールドに cascade:'all' を設定したい:
A.グルーヴィー
class A implements Serializable {
Integer a = 1 // This points to another class in my real code. I tried to make it as simple as possible. It has the same effect.
B b
static mapping = {
// It works fine if I comment out the following line (i.e. no composite key)
id composite:['a', 'b']
b cascade: 'all'
}
boolean equals(other) {
if (!(other instanceof A)) {
return false
}
other.a == a && other.b == b
}
int hashCode() {
def builder = new HashCodeBuilder()
builder.append a
builder.append b
builder.toHashCode()
}
}
B.グルーヴィー
class B {
String name = "Test"
}
Bootstrap.groovy で次のコードを実行しようとすると、例外が発生します。
B b = new B()
// It works fine if the next line is uncommented
//b.save(failOnError:true)
A a = new A()
a.b = b
a.save(flush:true, failOnError:true)
エラー:
| Error 2013-09-05 16:53:35,308 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: null
Message: null
Line | Method
->> 13 | doCall in BootStrap$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 308 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 301 | executeForEnvironment . . . . . in ''
| 277 | executeForCurrentEnvironment in ''
| 334 | innerRun . . . . . . . . . . . . in java.util.concurrent.FutureTask$Sync
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . . . . . . . . . . . . in java.lang.Thread
複合キーの使用が推奨されないことはわかっていますが、ここで何が問題なのかを知りたいです。