2012-03-11 9 views
0

私は、監査ログプラグインでgrails 1.3.7を使用しています。私はログに "user:PSam logged in at ..."のようなユーザーログインイベントをキャプチャしたい、プラグインにはonLoadイベントが定義されていないので、ドメインクラスに追加して、このイベントで自分の監査テーブルエントリを設定します。 )それを2 nullとして来ている私はここに二つの問題が生じていますユーザーログインの監査ログエントリを挿入する

def onLoad = { 
     try { 
     Graaudit aInstance = new Graaudit(); 
     aInstance.eventType= "User Log in" 
     aInstance.eventDescription = "User logged in" 
     aInstance.user_id = username 
     aInstance.save(flush:true); 
      println "username="+username 
      println aInstance; 
     } 
     catch (e){ 
      println(e.getMessage()) 
     } 
    } 

... 1)属性としてこのドメインクラスで定義されたユーザ名のプロパティを次のように だからGrailsのユーザードメインクラスで私がやります次のような例外がスローされます。No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

もう1つのアプローチはありますか? また、プラグインのaudi_logテーブルを使用して、onLoad()イベントの入力を設定できますか?事前に

おかげ取引で

答えて

1

ラップyoyrロジック:問題でしたし、それを解決し

def onLoad = { 
    Graaudit.withTransaction { 
     try { 
     Graaudit aInstance = new Graaudit(); 
     aInstance.eventType= "User Log in" 
     aInstance.eventDescription = "User logged in" 
     aInstance.user_id = username 
     aInstance.save(); 
     println "username="+username 
     println aInstance; 
     } 
     catch (e){ 
     println(e.getMessage()) 
     } 
    } 
} 
+0

どうもありがとう、... –

関連する問題