Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E2C144925 for ; Thu, 7 Jul 2011 16:43:23 +0000 (UTC) Received: (qmail 90691 invoked by uid 500); 7 Jul 2011 16:43:23 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 90639 invoked by uid 500); 7 Jul 2011 16:43:23 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 90631 invoked by uid 99); 7 Jul 2011 16:43:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2011 16:43:23 +0000 X-ASF-Spam-Status: No, hits=1.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of curtisr7@gmail.com designates 209.85.210.174 as permitted sender) Received: from [209.85.210.174] (HELO mail-iy0-f174.google.com) (209.85.210.174) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2011 16:43:16 +0000 Received: by iyb12 with SMTP id 12so1466141iyb.33 for ; Thu, 07 Jul 2011 09:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=qwR2G5eBv2ZKWv8+ViZMF9bQJSy7+AiCy7dHHo6vugU=; b=YwAwzSbsmYUqSZiw5zJP3U/ZW+O9TTkO8EJsNSE+ARBA43/XrfowtDncQEnLOjFaG4 VJv0vXlbiat8tsD/t4KsNHvfHkh80qMjDJ05xvD6N8X8FWdx4STTk8YqjcvF1pae0ZYl L25TR6tBIYBbPPtsKxg+7Soxca3xrIt1qIBa8= MIME-Version: 1.0 Received: by 10.43.49.68 with SMTP id uz4mr1070583icb.256.1310056975534; Thu, 07 Jul 2011 09:42:55 -0700 (PDT) Received: by 10.231.200.201 with HTTP; Thu, 7 Jul 2011 09:42:55 -0700 (PDT) In-Reply-To: References: <4E15A81E.4060307@iki.fi> Date: Thu, 7 Jul 2011 11:42:55 -0500 Message-ID: Subject: Re: Audit log with OpenJPA From: Rick Curtis To: users@openjpa.apache.org Content-Type: multipart/alternative; boundary=bcaec5299c59a989b704a77d6896 X-Virus-Checked: Checked by ClamAV on apache.org --bcaec5299c59a989b704a77d6896 Content-Type: text/plain; charset=ISO-8859-1 Perhaps you could use a separate PU for your audit logging? That should be safe to use inside of a lifecycle callback. On Thu, Jul 7, 2011 at 11:36 AM, Bengt Rodehav wrote: > Jari, > > Yes an asynchronous queue is definitely an option. I've actually used that > approach before. It makes a lot of sense when trying to achieve high > throughput since the audit logging can then be done on lower priority. > > I was however hoping to be able to use JPA for this since a queue increases > the complexity significantly (also regarding testing). > > Thanks, > > /Bengt > > 2011/7/7 Jari Fredriksson > > > 7.7.2011 14:05, Bengt Rodehav kirjoitti: > > > I'm using OpenJPA for persistence and would like to audit log any > changes > > > made to my entities. I serialize the objects to JSON (with Gson) and > > store > > > them in a separate table in the database. Since the audit log needs to > > have > > > the correct id's, the audit logging must take place after the entity > has > > > been persisted. > > > > > > I was hoping I could use the @PostPersist and @PostUpdate life cycle > > > callbacks for this. I do seem to have the right information available > and > > > the serialization works fine but I don't know how I can persist my > audit > > log > > > entries at this point. From what I've read, I'm not allowed to use the > > > entity manager in a "Post" lifecycle callback which of course makes > this > > > hard. > > > > > > What do you recommend? Is there a good place in JPA/OpenJPA where I > > > automatically can trigger the storing of an audit log entry as > described > > > above. Of course I can move this logic up from the persistence layer to > a > > > place where I can first have the entity manager persist my entity and > > then > > > explicitly call another service to do the audit log. However, this is a > > > pretty general mechanism that I would like to have automatic support > for > > in > > > my framework which is why I would like to have it pushed down into the > > > persistence layer. > > > > > > Any ideas? > > > > > > > I have not done anything like this, but some kind of queue and a > > separate processor for that queue might be a solution. > > > > Maybe some message queue? Or a singleton Hashtable containing entries, > > and a separate thread for persisting these to database. > > > > Something like that. > > > > > > > > -- > > > > AWAKE! FEAR! FIRE! FOES! AWAKE! > > FEAR! FIRE! FOES! > > AWAKE! AWAKE! > > -- J. R. R. Tolkien > > > > > -- *Rick Curtis* --bcaec5299c59a989b704a77d6896--