0

監査ログ プラグインを使用して grails 1.3.7 を使用しています。「user:PSam Logged in at ..」のようなユーザー ログイン イベントをログに記録したいのですが、プラグインにはonLoadイベントが定義されていないため、それをドメイン クラスに追加し、このイベントに独自の監査テーブル エントリを入力します。したがって、grails ユーザー ドメイン クラスでは、次のようにします。

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())
        }
    }

ここで 2 つの問題が発生しています... 1) このドメイン クラスで属性として定義されたユーザー名プロパティが null として表示されます 2) 次のような例外がスローされます。No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

ここで取るべき別のアプローチはありますか?また、プラグインの audi_log テーブルを使用して onLoad() イベント エントリを設定できますか?

前もって感謝します

4

1 に答える 1

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())
      }
    }
}
于 2012-03-12T08:49:12.507 に答える