我有2個域類;其中最糟糕的部分代表了一個電子郵件地址,包含用戶名和電子郵件地址本身。其他類表示一封電子郵件,與主題,發件人(一個電子郵件地址)和收件人(電子郵件地址列表):HasOne和HasMany具有相同的域類和級聯保存
class EmailMessage {
static hasMany = [ to: EmailAddress ]
EmailAddress from
String subject
}
class EmailAddress {
String name
String address
}
但正如我希望這個代碼不工作:
EmailMessage msg = new EmailMessage()
msg.from = new EmailAddress(name: "User 1", address: "[email protected]")
[new EmailAddress(name: "User 2", address: "[email protected]"), new EmailAddress(name: "User 3", address: "[email protected]")].each {
msg.addToTo(it)
}
msg.subject = "Asunto"
msg.save(failOnError: true)
我得到這個錯誤:
| Error 2013-08-14 21:08:40,362 [localhost-startStop-1] ERROR util.JDBCExceptionReporter - La columna "FROM_ID" no permite valores nulos (NULL)
NULL not allowed for column "FROM_ID"; SQL statement: insert into email_message (id, version, from_id, subject) values (null, ?, ?, ?) [23502-164]
| Error 2013-08-14 21:08:40,375 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: could not insert: [prueba.EmailMessage];
SQL [insert into email_message (id, version, from_id, subject) values (null, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [prueba.EmailMessage]
Message: could not insert: [prueba.EmailMessage]; SQL [insert into email_message (id, version, from_id, subject) values (null, ?, ?, ?)]; constraint [null];
nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [prueba.EmailMessage]
我不知道這甚至可以做到,或者級聯保存爲我想不工作。
我thik我嘗試過hasMany,belongsTo等每個類的所有組合,沒有成功。
我也讀過這個主題,但它沒有按預期工作Grails hasOne and hasMany same domain。
任何人都可以幫助我嗎?提前感謝和感謝。
我不知道這是否是相同的錯誤,但看一看:http://jira.grails.org/browse/GRAILS- 2736 – felipenasc