1
私は2つのオブジェクトを持っています。GRAILS GORM子を保存するときに親プロパティを自動的に更新する方法
TimeFrame{
hasMany=[activity:Activity]
Date startTime
Date endTime
Integer activeActivities
}
Activity{
belongsTo=[timeFrame:TimeFrame]
String name
String description
Date start
Date end
}
いつでも私は、更新を挿入するか、私は自動的に期限はありactiveActivitiesの数を更新する活動を削除します。私は
null id in com.application.tracker.Activity entry (don't flush the Session after an exception occurs).
エラーが出る...
def afterUpdate(){
try{
def num=0;
def now=new Date();
timeFrame.activities.each{i->
if(!i.end || i.end < now){
num+=1;
}
}
timeFrame.activeActivities=num;
timeFrame.save();
}
catch(e){
log.debug('Unable to update active tally on Activity update:'+e)
}
}
などのGROMイベントメソッドを追加する場合でも、これを回避する方法は何ですか?
'withNewSession'を使用していないため、' afterUpdate'の中に保存できません。ドキュメント:http://docs.grails.org/2.4.x/guide/GORM.html#eventsAutoTimestamping –
ahaを参照してください。 Critical sentence ... "幸運なことに、withNewSessionメソッドを使用すると、異なる基本セッションを使用していても、同じトランザクションJDBC接続を共有できます。 – user2782001