Re: Enhancement skipping field

2011-07-12 Thread Matthew Goodson
Hi, we are getting closer!

We added a strategy the uuid field

@Persistent
@Strategy("com.datastax.hectorjpa.strategy.NoOpHandler")
private UUID id;

So now it successfully enhances the class which now looks like this

@javax.persistence.metamodel.StaticMetamodel
(value=com.spidertracks.aviator.model.user.Phone.class)
@javax.annotation.Generated
(value="org.apache.openjpa.persistence.meta.AnnotationProcessor6",date="Wed
Jul 13 13:00:16 NZST 2011")
public class Phone_ {
public static volatile SingularAttribute countryIdd;
public static volatile SingularAttribute id;
public static volatile SingularAttribute iddCountryCode;
public static volatile SingularAttribute number;
public static volatile SingularAttribute type;
}

But when we go to load something it gets the list of fields, which includes
the id field, but this field is then stripped out when he meta data is
resolved.
This happens on line 164 of the ClassMetaData class in the resolveMeta
method and I get the following warning.

2011-07-13 03:16:23,295Z  WARN [main]  Field "
com.spidertracks.aviator.model.user.Phone.id" is not a type that is
persistent by default.  If you want this field to be persistent, you have to
explicitly set it to persistent in your metadata.

Thanks

On Wed, Jul 13, 2011 at 9:25 AM, Rick Curtis  wrote:

> Todd -
>
> I'm stretching a bit here as I've never actually experimented with this
> code but I'd start out by looking at
> org.apache.openjpa.persistence.jdbc.annotations.NonstandardMappingEntity
> and
>
> org.apache.openjpa.persistence.jdbc.annotations.TestNonstandardMappingAnnotations.
>
> It appears that you could add a @Strategy annotation to your UUID field and
> point it at your handler. That *should* auto-magically wire up the proper
> calls to you handler. If/when you get that working, it looks like you
> should
> be able to add this strategy(UUID->customer handler) to the mapping
> defaults.
>
> On Tue, Jul 12, 2011 at 3:58 PM, Todd Nine  wrote:
>
> > Hey Rick,
> >  Adding the handler makes the field appear in the field list for my
> > plugin.  However my plugin currently doesn't support value handlers.  I
> > need to add this functionality, what is the best class to use as an
> > example for reading this meta data and invoking it at runtime?
> >
> > Thanks,
> > Todd
> >
> > On Tue, 2011-07-12 at 11:18 -0500, Rick Curtis wrote:
> >
> > > Todd -
> > >
> > > I don't think the problem is that the enhancer skips the field, its the
> > fact
> > > that we don't know how the map the UUID field. You might be able to
> write
> > a
> > > customer value handler [1] ? Take a look at that and see if it would
> work
> > > for you.
> > >
> > > Let me know how it goes.
> > >
> > > [1]
> > >
> >
> http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_mapping_custom_vhandler
> > >
> > > On Sun, Jul 10, 2011 at 3:12 PM, Todd Nine 
> > wrote:
> > >
> > > > Hey guys,
> > > >  I'm also involved in this project, I'm the developer for this
> plugin.
> > > >
> > > > https://github.com/riptano/hector-jpa/
> > > >
> > > > The UUID class is used extensively by quite a few Cassandra
> developers.
> > > > We've successfully used it as an identity, and my plug in recognizes
> > the
> > > > data type and can correctly serialize it.  However, when not used in
> > > > either a composite identity or an identity, it appears that Open JPA
> > > > does not correctly interpret the type and create an instance of a
> > > > persistent UUID in the list of fields for the entity.
> > > >
> > > > Here is  the UUID class we're using.
> > > >
> > > > http://johannburkard.de/software/uuid/
> > > >
> > > > I definitely want to provide native support for this value in my
> plugin
> > > > over string converter serialization.  How can I get the open JPA
> > > > enhancer to add it as a persistent field to the Entity during
> > > > enhancement?  I'll need to document this for my plugin, any help
> would
> > > > be greatly appreciated.
> > > >
> > > > Todd
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On Fri, 2011-07-08 at 09:08 -0500, Rick Curtis wrote:
> > > >
> > > > > Should your UUID class have an embeddable annotation also?
> > > > >
> > > > > On Thu, Jul 7, 2011 at 4:27 PM, Matthew Goodson
> > > > > wrote:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > > Kevin: We're using maven and it is picking up the Phone_ class
> and
> > > > > > generating the warning
> > > > > >
> > > > > > here's the link for the uuid class that we're using
> > > > > >
> > > > > >
> > > >
> >
> https://github.com/stephenc/eaio-uuid/blob/master/src/main/java/com/eaio/uuid/UUID.java
> > > > > >
> > > > > > And the persistence xml...
> > > > > >
> > > > > > http://java.sun.com/xml/ns/persistence";
> > > > > >  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > > > >  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> > > > > > http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd";
> > > > > >  version="2.0">
> > > > > >  

Re: Problems with load time enhancement and Spring's TomcatInstrumentableClassLoader

2011-07-12 Thread Pinaki Poddar
Hi Andrew,
  Your decision to opt for build-time enhancement is the right choice. The
wrinkles around the mechanics of bytecode enhancement process is the
responsibility of OpenJPA team. And we perhaps havn't done a good job of it
from a usability point of view. Moreover, we have introduced several
alternatives that can bypass bytecode enhancement at build time. However,
these mechanics often carry forward edge errors that manifest as runtime
errors and are difficult to track. 
 
Here are few suggestions. Please add our perspectives 
  a) emphasize the import of bytecode enhancement at build time in our
document. The XML 
  b) make the mechanics more accessible -- they exist but are hard to
find 
  c) block or at least inhibit other modes such that the developer can
do the right thing and not get tangled in a weave at runtime. 
   

-
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Problems-with-load-time-enhancement-and-Spring-s-TomcatInstrumentableClassLoader-tp6554347p6577479.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Problems with load time enhancement and Spring's TomcatInstrumentableClassLoader

2011-07-12 Thread Andrew Thompson
Pinaki,

The culprit in my case was maven/m2eclipse which by default executes the
maven builder on every change.  This wasn't an issue at all related to
openjpa other then it was a required step within the build.  

While that default behavior can, and should, be modified.  My experience
was that it added confusion for developers who previously didn't have to
know about byte code enhancement or even a maven build.

-Andy

On Tue, 2011-07-12 at 17:56 -0700, Pinaki Poddar wrote: 
> > even then that introduced a minute or two of build time in eclipse
> How are you invoking build-time enhancement in Eclipse?
> 
> > which without hackery insists on a full project build. 
> Who insists on a full project build on minor changes?
> 
> -
> Pinaki Poddar
> Chair, Apache OpenJPA Project
> --
> View this message in context: 
> http://openjpa.208410.n2.nabble.com/Problems-with-load-time-enhancement-and-Spring-s-TomcatInstrumentableClassLoader-tp6554347p6577376.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.



Re: Problems with load time enhancement and Spring's TomcatInstrumentableClassLoader

2011-07-12 Thread Pinaki Poddar
> even then that introduced a minute or two of build time in eclipse
How are you invoking build-time enhancement in Eclipse?

> which without hackery insists on a full project build. 
Who insists on a full project build on minor changes?

-
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Problems-with-load-time-enhancement-and-Spring-s-TomcatInstrumentableClassLoader-tp6554347p6577376.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: FetchPlan question

2011-07-12 Thread Pinaki Poddar
> Thoughts? 
I think you are correct. 
Our removeField() has weak semantics than excludeFields() - a method we do
not have!
But please run some test and let me know. 

If you tweaking things, see FetchPlan.requiresFetch() 

-
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: 
http://openjpa.208410.n2.nabble.com/FetchPlan-question-tp6577007p6577367.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Audit log with OpenJPA

2011-07-12 Thread Pinaki Poddar
Hi,
  Try setting cascade=CascadeTpe.ALL on @OneToMany annotation of 
private Collection auditLog; 



-
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Audit-log-with-OpenJPA-tp6557932p6577022.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


FetchPlan question

2011-07-12 Thread Rick Curtis
Should I be able to remove an eager field from the default fetch plan? For
example, I have the following Entity snippet:

@Entity
public class ManyEagerNode {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected int id;

@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
Set setConnections = new HashSet();
...
}

and I would like to be able to mark the setConnections field as LAZY. I
thought I should be able to do something along these lines...

FetchPlan fp = em.getFetchPlan()
fp.removeField("org.apache.openjpa.persistence.graph.ManyEagerNode.setConnections");

I browsed the code and it's quite obvious that this will not work. Is this
by design, or an oversight? The docs seem to imply that the fetch plan can
used to mark fields as Eager, but not vice versa. I assume I could create a
new, non-default fetch plan and I could manually add my fields but I
would like to work directly with the default fetch plan.

Thoughts?

-- 
*Rick Curtis*


Re: Enhancement skipping field

2011-07-12 Thread Rick Curtis
Todd -

I'm stretching a bit here as I've never actually experimented with this
code but I'd start out by looking at
org.apache.openjpa.persistence.jdbc.annotations.NonstandardMappingEntity and
org.apache.openjpa.persistence.jdbc.annotations.TestNonstandardMappingAnnotations.

It appears that you could add a @Strategy annotation to your UUID field and
point it at your handler. That *should* auto-magically wire up the proper
calls to you handler. If/when you get that working, it looks like you should
be able to add this strategy(UUID->customer handler) to the mapping
defaults.

On Tue, Jul 12, 2011 at 3:58 PM, Todd Nine  wrote:

> Hey Rick,
>  Adding the handler makes the field appear in the field list for my
> plugin.  However my plugin currently doesn't support value handlers.  I
> need to add this functionality, what is the best class to use as an
> example for reading this meta data and invoking it at runtime?
>
> Thanks,
> Todd
>
> On Tue, 2011-07-12 at 11:18 -0500, Rick Curtis wrote:
>
> > Todd -
> >
> > I don't think the problem is that the enhancer skips the field, its the
> fact
> > that we don't know how the map the UUID field. You might be able to write
> a
> > customer value handler [1] ? Take a look at that and see if it would work
> > for you.
> >
> > Let me know how it goes.
> >
> > [1]
> >
> http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_mapping_custom_vhandler
> >
> > On Sun, Jul 10, 2011 at 3:12 PM, Todd Nine 
> wrote:
> >
> > > Hey guys,
> > >  I'm also involved in this project, I'm the developer for this plugin.
> > >
> > > https://github.com/riptano/hector-jpa/
> > >
> > > The UUID class is used extensively by quite a few Cassandra developers.
> > > We've successfully used it as an identity, and my plug in recognizes
> the
> > > data type and can correctly serialize it.  However, when not used in
> > > either a composite identity or an identity, it appears that Open JPA
> > > does not correctly interpret the type and create an instance of a
> > > persistent UUID in the list of fields for the entity.
> > >
> > > Here is  the UUID class we're using.
> > >
> > > http://johannburkard.de/software/uuid/
> > >
> > > I definitely want to provide native support for this value in my plugin
> > > over string converter serialization.  How can I get the open JPA
> > > enhancer to add it as a persistent field to the Entity during
> > > enhancement?  I'll need to document this for my plugin, any help would
> > > be greatly appreciated.
> > >
> > > Todd
> > >
> > >
> > >
> > >
> > >
> > > On Fri, 2011-07-08 at 09:08 -0500, Rick Curtis wrote:
> > >
> > > > Should your UUID class have an embeddable annotation also?
> > > >
> > > > On Thu, Jul 7, 2011 at 4:27 PM, Matthew Goodson
> > > > wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > Kevin: We're using maven and it is picking up the Phone_ class and
> > > > > generating the warning
> > > > >
> > > > > here's the link for the uuid class that we're using
> > > > >
> > > > >
> > >
> https://github.com/stephenc/eaio-uuid/blob/master/src/main/java/com/eaio/uuid/UUID.java
> > > > >
> > > > > And the persistence xml...
> > > > >
> > > > > http://java.sun.com/xml/ns/persistence";
> > > > >  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > > >  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> > > > > http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd";
> > > > >  version="2.0">
> > > > >  
> > > > >
> > > > >
> > >
> org.apache.openjpa.persistence.PersistenceProviderImpl
> > > > >
> > > > >
> > > > >
> > > > >com.spidertracks.aviator.model.Persistable
> > > > >com.spidertracks.aviator.model.UuidEntity
> > > > >
> > > > >
> > > > >
> > > > >
>  com.spidertracks.aviator.model.cluster.ClusterRegion
> > > > >
>  com.spidertracks.aviator.model.cluster.SpiderRegion
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > >
> com.spidertracks.aviator.model.security.AviatorRememberMeToken
> > > > >
> > > > >
> > > > >
> > >
>  com.spidertracks.aviator.model.sms.PhoneValidationMessage
> > > > >
>  com.spidertracks.aviator.model.sms.ReceivedSmsMessage
> > > > >com.spidertracks.aviator.model.sms.SentSmsMessage
> > > > >com.spidertracks.aviator.model.sms.SmsMessage
> > > > >
>  com.spidertracks.aviator.model.sms.SosClosedMessage
> > > > >
> > > > >
> > >
> com.spidertracks.aviator.model.sms.SosInvalidResponseMessage
> > > > >com.spidertracks.aviator.model.sms.SosMessage
> > > > >
>  com.spidertracks.aviator.model.sms.SosTierOneMessage
> > > > >
> > > > >
> > > > >
> > >
> com.spidertracks.aviator.model.sms.SosTierOneReopenedUserMessage
> > > > >
>  com.spidertracks.aviator.model.sms.SosTierTwoMessage
> > > > >
> > > > >
> > > > >
> > >
> com.spidertracks.aviator.model.sms.SosTierTwoReopenedUserMessage
> > > > >
> > >
>  com.spidertracks.aviator.model.sms.SosTierTwoUserMessage
> > > > >
> > > > >
> > > > >
> > > > >
>  com.spidertracks.aviator.model.sos.ContactedPerson
> > > > 

Re: Enhancement skipping field

2011-07-12 Thread Todd Nine
Hey Rick,
  Adding the handler makes the field appear in the field list for my
plugin.  However my plugin currently doesn't support value handlers.  I
need to add this functionality, what is the best class to use as an
example for reading this meta data and invoking it at runtime?

Thanks,
Todd

On Tue, 2011-07-12 at 11:18 -0500, Rick Curtis wrote:

> Todd -
> 
> I don't think the problem is that the enhancer skips the field, its the fact
> that we don't know how the map the UUID field. You might be able to write a
> customer value handler [1] ? Take a look at that and see if it would work
> for you.
> 
> Let me know how it goes.
> 
> [1]
> http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_mapping_custom_vhandler
> 
> On Sun, Jul 10, 2011 at 3:12 PM, Todd Nine  wrote:
> 
> > Hey guys,
> >  I'm also involved in this project, I'm the developer for this plugin.
> >
> > https://github.com/riptano/hector-jpa/
> >
> > The UUID class is used extensively by quite a few Cassandra developers.
> > We've successfully used it as an identity, and my plug in recognizes the
> > data type and can correctly serialize it.  However, when not used in
> > either a composite identity or an identity, it appears that Open JPA
> > does not correctly interpret the type and create an instance of a
> > persistent UUID in the list of fields for the entity.
> >
> > Here is  the UUID class we're using.
> >
> > http://johannburkard.de/software/uuid/
> >
> > I definitely want to provide native support for this value in my plugin
> > over string converter serialization.  How can I get the open JPA
> > enhancer to add it as a persistent field to the Entity during
> > enhancement?  I'll need to document this for my plugin, any help would
> > be greatly appreciated.
> >
> > Todd
> >
> >
> >
> >
> >
> > On Fri, 2011-07-08 at 09:08 -0500, Rick Curtis wrote:
> >
> > > Should your UUID class have an embeddable annotation also?
> > >
> > > On Thu, Jul 7, 2011 at 4:27 PM, Matthew Goodson
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > Kevin: We're using maven and it is picking up the Phone_ class and
> > > > generating the warning
> > > >
> > > > here's the link for the uuid class that we're using
> > > >
> > > >
> > https://github.com/stephenc/eaio-uuid/blob/master/src/main/java/com/eaio/uuid/UUID.java
> > > >
> > > > And the persistence xml...
> > > >
> > > > http://java.sun.com/xml/ns/persistence";
> > > >  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > >  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> > > > http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd";
> > > >  version="2.0">
> > > >  
> > > >
> > > >
> > org.apache.openjpa.persistence.PersistenceProviderImpl
> > > >
> > > >
> > > >
> > > >com.spidertracks.aviator.model.Persistable
> > > >com.spidertracks.aviator.model.UuidEntity
> > > >
> > > >
> > > >
> > > >com.spidertracks.aviator.model.cluster.ClusterRegion
> > > >com.spidertracks.aviator.model.cluster.SpiderRegion
> > > >
> > > >
> > > >
> > > >
> > > >
> > com.spidertracks.aviator.model.security.AviatorRememberMeToken
> > > >
> > > >
> > > >
> >  com.spidertracks.aviator.model.sms.PhoneValidationMessage
> > > >com.spidertracks.aviator.model.sms.ReceivedSmsMessage
> > > >com.spidertracks.aviator.model.sms.SentSmsMessage
> > > >com.spidertracks.aviator.model.sms.SmsMessage
> > > >com.spidertracks.aviator.model.sms.SosClosedMessage
> > > >
> > > >
> > com.spidertracks.aviator.model.sms.SosInvalidResponseMessage
> > > >com.spidertracks.aviator.model.sms.SosMessage
> > > >com.spidertracks.aviator.model.sms.SosTierOneMessage
> > > >
> > > >
> > > >
> > com.spidertracks.aviator.model.sms.SosTierOneReopenedUserMessage
> > > >com.spidertracks.aviator.model.sms.SosTierTwoMessage
> > > >
> > > >
> > > >
> > com.spidertracks.aviator.model.sms.SosTierTwoReopenedUserMessage
> > > >
> >  com.spidertracks.aviator.model.sms.SosTierTwoUserMessage
> > > >
> > > >
> > > >
> > > >com.spidertracks.aviator.model.sos.ContactedPerson
> > > >com.spidertracks.aviator.model.sos.OpenHistory
> > > >com.spidertracks.aviator.model.sos.SoS
> > > >
> > > >
> > > >com.spidertracks.aviator.model.spider.Spider
> > > >
> > > >
> > > >
> > > >
> > > >
> > com.spidertracks.aviator.model.spider.message.AlertAcknowlege
> > > >
> > > >
> > > >
> > com.spidertracks.aviator.model.spider.message.ConfigMessageUpdate
> > > >
> > > >
> > > >
> > com.spidertracks.aviator.model.spider.message.DistanceSettings
> > > >
> > > >
> > > >
> > com.spidertracks.aviator.model.spider.message.MobileTerminatedConfirmation
> > > >
> > > >
> > com.spidertracks.aviator.model.spider.message.SpiderUpdate
> > > >
> > > >
> > > >
> > com.spidertracks.aviator.model.spider.message.SpiderwatchSettings
> > > >
> > > >
> > > >
> > com.spidertracks.aviator.model.spider.message.TimeDistanceSettings
> > > >
> > > >
> > com.spidertracks.aviator.model.spider.message

Re: Audit log with OpenJPA

2011-07-12 Thread Bengt Rodehav
Jim,

I tried your approach (I think) but got the following exception:

*
> org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged
> object in persistent field
> "se.digia.maia.common.persistence.EntityBase.auditLog se.digia.maia.common.auditlog.domain.AuditLog>" during flush.  However, this
> field does not allow cascade persist. Set the cascade attribute for this
> field to CascadeType.PERSIST or CascadeType.ALL (JPA annotations) or
> "persist" or "all" (JPA orm.xml), or enable cascade-persist globally, or
> manually persist the related field value prior to flushing. You cannot flush
> unmanaged objects or graphs that have persistent associations to unmanaged
> objects.
> **FailedObject: se.digia.maia.common.auditlog.domain.AuditLog@39bc82
> ** at
> org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:767)
> ** at
> org.apache.openjpa.kernel.SingleFieldManager.preFlushPCs(SingleFieldManager.java:748)
> ** at
> org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:642)
> ** at
> org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:575)
> ** at
> org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:491)
> ** at
> org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2957)
> ** at
> org.apache.openjpa.kernel.PDirtyState.beforeFlush(PDirtyState.java:38)
> ** at
> org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1047)
> ** at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2077)
> ** at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2037)
> ** at
> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1955)
> ** at
> org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
> ** at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1479)
> ** at
> org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:925)
> ** at
> org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:560)
> ** at
> se.digia.maia.core.bu.test.CRUDTest.updateBusinessUnitTest(CRUDTest.java:141)
> *


I use OpenJPA 2.0.1. This is my relationship to the audit log table:

  @OneToMany
  @JoinTable(
name = "ENTITY_ALOG",
joinColumns = @JoinColumn(name = "ENTITY_ID"),
inverseJoinColumns = @JoinColumn(name = "ALOG_ID"))
  private Collection auditLog;

This is my @PreUpdate method:

  @PreUpdate
  public void beforeUpdate() {
setUpdatedWhen(Calendar.getInstance());
setUpdatedBy(Session.getCurrentUser());
if (this.getClass().getAnnotation(Audit.class) != null) {
  AuditLog al = new AuditLog();
  al.setLogEntry("serialization of object");
  auditLog.add(al);
}
  }

OpenJPA doesn't seem to like this. What did you do differently?

/Bengt

2011/7/12 Bengt Rodehav 

> OK - I didn't know that.
>
> I agree that it would be nice if the OpenJPA guys would support this
> behaviour. My experience of standards (like JPA) is that the standard itself
> is rarely enough for production purposes. Things outside of the standard
> need to be in place as well. Then, after a while, the standard will
> sometimes adapt to reality and incorporate what has become the de facto
> standard.
>
> In this case, it is clear that the behaviour of the life-cycle callback
> methods is not defined enough in the standard. The implementations should
> therefore create a de facto standard. Let's hope they do...
>
> /Bengt
>
> 2011/7/12 Jim Talbut 
>
>> On 12/07/2011 09:33, Bengt Rodehav wrote:
>>
>>> Why do you think that your approach is not supported by JPA? From other
>>> posts on this list I've seen that you are allowed to add/enrich your
>>> entity
>>> in the PreUpdate/PreCreate callbacks. That's all you are doing right.
>>> Then
>>> JPA persists your enriched entities.
>>>
>>
>> I asked on this list a few months ago:
>> http://web.archiveorange.com/**archive/v/tXrrxw9bXkttUykS7B6K
>>
>> You can change the state of entities, but creating new entities is not
>> permitted by the JPA spec.
>> At the moment it does work, and I now what I'm going to do if it stops
>> working, so I'm happy.
>> I'd be happier if OpenJPA explicitly supported it, but it doesn't keep me
>> awake at night.
>>
>> Jim
>>
>
>


Re: Audit log with OpenJPA

2011-07-12 Thread Bengt Rodehav
OK - I didn't know that.

I agree that it would be nice if the OpenJPA guys would support this
behaviour. My experience of standards (like JPA) is that the standard itself
is rarely enough for production purposes. Things outside of the standard
need to be in place as well. Then, after a while, the standard will
sometimes adapt to reality and incorporate what has become the de facto
standard.

In this case, it is clear that the behaviour of the life-cycle callback
methods is not defined enough in the standard. The implementations should
therefore create a de facto standard. Let's hope they do...

/Bengt

2011/7/12 Jim Talbut 

> On 12/07/2011 09:33, Bengt Rodehav wrote:
>
>> Why do you think that your approach is not supported by JPA? From other
>> posts on this list I've seen that you are allowed to add/enrich your
>> entity
>> in the PreUpdate/PreCreate callbacks. That's all you are doing right. Then
>> JPA persists your enriched entities.
>>
>
> I asked on this list a few months ago:
> http://web.archiveorange.com/**archive/v/tXrrxw9bXkttUykS7B6K
>
> You can change the state of entities, but creating new entities is not
> permitted by the JPA spec.
> At the moment it does work, and I now what I'm going to do if it stops
> working, so I'm happy.
> I'd be happier if OpenJPA explicitly supported it, but it doesn't keep me
> awake at night.
>
> Jim
>


RE: Logging questions

2011-07-12 Thread Jason Pyeron
> -Original Message-
> From: Rick Curtis [mailto:curti...@gmail.com] 
> Sent: Tuesday, July 12, 2011 14:00
> To: users@openjpa.apache.org
> Subject: Re: Logging questions
> 
> What do you have set for a configuration property? Have you 
> tried openjpa.Log=commons?






 
  












Also worth noting, it burps out at the very start:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details.
log4j:WARN No appenders could be found for logger (openjpa.Runtime).
log4j:WARN Please initialize the log4j system properly.

> 
> On Tue, Jul 12, 2011 at 12:48 PM, Jason Pyeron 
>  wrote:
> 
> > > -Original Message-
> > > From: Rick Curtis [mailto:curti...@gmail.com]
> > > Sent: Tuesday, July 12, 2011 12:22
> > > To: users@openjpa.apache.org
> > > Subject: Re: Logging questions
> > >
> > > Jason -
> > >
> > > Sorry about the slow reply, I must have missed this one somehow.
> > >
> > > > 1. Is it possible to (dynamically) change the logging
> > > levels at runtime?
> > > No, I don't believe so.
> > >
> > > > 2. Could someone elaborate more on the usage of 
> java.util.logging 
> > > > by
> > > setting to value to "commons"?
> > > What more are you looking for?
> >
> > Hmm.. It does not seem to use j.u.l for logging when set to 
> commons on 
> > Sun Java
> > 1.6 64 bit.
> >
> > My formatter would output like:
> >
> > Jul 12, 2011 12:32:10 PM 
> org.apache.coyote.http11.Http11BaseProtocol 
> > init
> > INFO: Initializing Coyote HTTP/1.1 on http-8080
> >
> > But I am getting interspersed [double CR added for clarity]:
> >
> > 3500  localhost  WARN   [main] openjpa.MetaData - Found 
> duplicate generator
> > "seq" in "class
> > 
> xxx.RecycledVoucherCheckFile".
> > Ignoring.
> >
> >
> > Jul 12, 2011 1:43:58 PM
> > xxx.TestClaimModels setUp
> > FINE: factory created
> >
> >
> > 203  localhost  INFO   [main] openjpa.Runtime - Starting OpenJPA
> > 2.1.0-SNAPSHOT
> >
> >
> > 484  localhost  INFO   [main] openjpa.jdbc.JDBC - Using 
> dictionary class
> > "org.apache.openjpa.jdbc.sql.OracleDictionary".
> >
> >
> > Jul 12, 2011 1:44:07 PM
> > xxx.TestClaimModels setUp
> > FINE: em created
> >
> >
> > Jul 12, 2011 1:44:07 PM
> > xxx.TestClaimModels
> > testListAllObjects
> > INFO: class
> > xxx.AdditionalErrorInfo:
> > before
> >
> >
> > 14078  localhost  TRACE  [main] openjpa.jdbc.SQL -  >
> >
> >
> >
> >
> > >
> > > On Wed, Jun 29, 2011 at 3:55 PM, Jason Pyeron  
> > > wrote:
> > >
> > > > Using 2.1.x I have 2 questions I was unable to google for an 
> > > > answer after reading the manual.
> > > >
> > > > 1. Is it possible to (dynamically) change the logging
> > > levels at runtime?
> > > >
> > > > 2. Could someone elaborate more on the usage of
> > > java.util.logging by
> > > > setting the value to "commons"?
> > > >
> > > > -Jason
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-   -
- Jason Pyeron  PD Inc. http://www.pdinc.us -
- Principal Consultant  10 West 24th Street #100-
- +1 (443) 269-1555 x333Baltimore, Maryland 21218   -
-   -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.

 



Re: Logging questions

2011-07-12 Thread Rick Curtis
What do you have set for a configuration property? Have you tried
openjpa.Log=commons?

On Tue, Jul 12, 2011 at 12:48 PM, Jason Pyeron  wrote:

> > -Original Message-
> > From: Rick Curtis [mailto:curti...@gmail.com]
> > Sent: Tuesday, July 12, 2011 12:22
> > To: users@openjpa.apache.org
> > Subject: Re: Logging questions
> >
> > Jason -
> >
> > Sorry about the slow reply, I must have missed this one somehow.
> >
> > > 1. Is it possible to (dynamically) change the logging
> > levels at runtime?
> > No, I don't believe so.
> >
> > > 2. Could someone elaborate more on the usage of java.util.logging by
> > setting to value to "commons"?
> > What more are you looking for?
>
> Hmm.. It does not seem to use j.u.l for logging when set to commons on Sun
> Java
> 1.6 64 bit.
>
> My formatter would output like:
>
> Jul 12, 2011 12:32:10 PM org.apache.coyote.http11.Http11BaseProtocol init
> INFO: Initializing Coyote HTTP/1.1 on http-8080
>
> But I am getting interspersed [double CR added for clarity]:
>
> 3500  localhost  WARN   [main] openjpa.MetaData - Found duplicate generator
> "seq" in "class
> xxx.RecycledVoucherCheckFile".
> Ignoring.
>
>
> Jul 12, 2011 1:43:58 PM
> xxx.TestClaimModels setUp
> FINE: factory created
>
>
> 203  localhost  INFO   [main] openjpa.Runtime - Starting OpenJPA
> 2.1.0-SNAPSHOT
>
>
> 484  localhost  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
> "org.apache.openjpa.jdbc.sql.OracleDictionary".
>
>
> Jul 12, 2011 1:44:07 PM
> xxx.TestClaimModels setUp
> FINE: em created
>
>
> Jul 12, 2011 1:44:07 PM
> xxx.TestClaimModels
> testListAllObjects
> INFO: class
> xxx.AdditionalErrorInfo:
> before
>
>
> 14078  localhost  TRACE  [main] openjpa.jdbc.SQL - 
>
>
>
>
> >
> > On Wed, Jun 29, 2011 at 3:55 PM, Jason Pyeron
> >  wrote:
> >
> > > Using 2.1.x I have 2 questions I was unable to google for an answer
> > > after reading the manual.
> > >
> > > 1. Is it possible to (dynamically) change the logging
> > levels at runtime?
> > >
> > > 2. Could someone elaborate more on the usage of
> > java.util.logging by
> > > setting the value to "commons"?
> > >
> > > -Jason
> > >
> > > --
> > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> > > -   -
> > > - Jason Pyeron  PD Inc. http://www.pdinc.us -
> > > - Principal Consultant  10 West 24th Street #100-
> > > - +1 (443) 269-1555 x333Baltimore, Maryland 21218   -
> > > -   -
> > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> > > This message is copyright PD Inc, subject to license 20080407P00.
> > >
> > >
> > >
> >
> >
> > --
> > *Rick Curtis*
> >
>
>
>
> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> -   -
> - Jason Pyeron  PD Inc. http://www.pdinc.us -
> - Principal Consultant  10 West 24th Street #100-
> - +1 (443) 269-1555 x333Baltimore, Maryland 21218   -
> -   -
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> This message is copyright PD Inc, subject to license 20080407P00.
>
>
>
>


-- 
*Rick Curtis*


RE: Logging questions

2011-07-12 Thread Jason Pyeron
> -Original Message-
> From: Rick Curtis [mailto:curti...@gmail.com] 
> Sent: Tuesday, July 12, 2011 12:22
> To: users@openjpa.apache.org
> Subject: Re: Logging questions
> 
> Jason -
> 
> Sorry about the slow reply, I must have missed this one somehow.
> 
> > 1. Is it possible to (dynamically) change the logging 
> levels at runtime?
> No, I don't believe so.
> 
> > 2. Could someone elaborate more on the usage of java.util.logging by
> setting to value to "commons"?
> What more are you looking for?

Hmm.. It does not seem to use j.u.l for logging when set to commons on Sun Java
1.6 64 bit. 

My formatter would output like: 

Jul 12, 2011 12:32:10 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080

But I am getting interspersed [double CR added for clarity]:

3500  localhost  WARN   [main] openjpa.MetaData - Found duplicate generator
"seq" in "class
xxx.RecycledVoucherCheckFile".
Ignoring.


Jul 12, 2011 1:43:58 PM
xxx.TestClaimModels setUp
FINE: factory created


203  localhost  INFO   [main] openjpa.Runtime - Starting OpenJPA 2.1.0-SNAPSHOT


484  localhost  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
"org.apache.openjpa.jdbc.sql.OracleDictionary".


Jul 12, 2011 1:44:07 PM
xxx.TestClaimModels setUp
FINE: em created


Jul 12, 2011 1:44:07 PM
xxx.TestClaimModels testListAllObjects
INFO: class xxx.AdditionalErrorInfo:
before


14078  localhost  TRACE  [main] openjpa.jdbc.SQL -  
> On Wed, Jun 29, 2011 at 3:55 PM, Jason Pyeron 
>  wrote:
> 
> > Using 2.1.x I have 2 questions I was unable to google for an answer 
> > after reading the manual.
> >
> > 1. Is it possible to (dynamically) change the logging 
> levels at runtime?
> >
> > 2. Could someone elaborate more on the usage of 
> java.util.logging by 
> > setting the value to "commons"?
> >
> > -Jason
> >
> > --
> > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> > -   -
> > - Jason Pyeron  PD Inc. http://www.pdinc.us -
> > - Principal Consultant  10 West 24th Street #100-
> > - +1 (443) 269-1555 x333Baltimore, Maryland 21218   -
> > -   -
> > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> > This message is copyright PD Inc, subject to license 20080407P00.
> >
> >
> >
> 
> 
> --
> *Rick Curtis*
> 



--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-   -
- Jason Pyeron  PD Inc. http://www.pdinc.us -
- Principal Consultant  10 West 24th Street #100-
- +1 (443) 269-1555 x333Baltimore, Maryland 21218   -
-   -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.

 



Re: Logging questions

2011-07-12 Thread Rick Curtis
Jason -

Sorry about the slow reply, I must have missed this one somehow.

> 1. Is it possible to (dynamically) change the logging levels at runtime?
No, I don't believe so.

> 2. Could someone elaborate more on the usage of java.util.logging by
setting to value to "commons"?
What more are you looking for?

On Wed, Jun 29, 2011 at 3:55 PM, Jason Pyeron  wrote:

> Using 2.1.x I have 2 questions I was unable to google for an answer after
> reading the manual.
>
> 1. Is it possible to (dynamically) change the logging levels at runtime?
>
> 2. Could someone elaborate more on the usage of java.util.logging by
> setting the
> value to "commons"?
>
> -Jason
>
> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> -   -
> - Jason Pyeron  PD Inc. http://www.pdinc.us -
> - Principal Consultant  10 West 24th Street #100-
> - +1 (443) 269-1555 x333Baltimore, Maryland 21218   -
> -   -
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> This message is copyright PD Inc, subject to license 20080407P00.
>
>
>


-- 
*Rick Curtis*


Re: Enhancement skipping field

2011-07-12 Thread Rick Curtis
Todd -

I don't think the problem is that the enhancer skips the field, its the fact
that we don't know how the map the UUID field. You might be able to write a
customer value handler [1] ? Take a look at that and see if it would work
for you.

Let me know how it goes.

[1]
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_mapping_custom_vhandler

On Sun, Jul 10, 2011 at 3:12 PM, Todd Nine  wrote:

> Hey guys,
>  I'm also involved in this project, I'm the developer for this plugin.
>
> https://github.com/riptano/hector-jpa/
>
> The UUID class is used extensively by quite a few Cassandra developers.
> We've successfully used it as an identity, and my plug in recognizes the
> data type and can correctly serialize it.  However, when not used in
> either a composite identity or an identity, it appears that Open JPA
> does not correctly interpret the type and create an instance of a
> persistent UUID in the list of fields for the entity.
>
> Here is  the UUID class we're using.
>
> http://johannburkard.de/software/uuid/
>
> I definitely want to provide native support for this value in my plugin
> over string converter serialization.  How can I get the open JPA
> enhancer to add it as a persistent field to the Entity during
> enhancement?  I'll need to document this for my plugin, any help would
> be greatly appreciated.
>
> Todd
>
>
>
>
>
> On Fri, 2011-07-08 at 09:08 -0500, Rick Curtis wrote:
>
> > Should your UUID class have an embeddable annotation also?
> >
> > On Thu, Jul 7, 2011 at 4:27 PM, Matthew Goodson
> > wrote:
> >
> > > Hi,
> > >
> > > Kevin: We're using maven and it is picking up the Phone_ class and
> > > generating the warning
> > >
> > > here's the link for the uuid class that we're using
> > >
> > >
> https://github.com/stephenc/eaio-uuid/blob/master/src/main/java/com/eaio/uuid/UUID.java
> > >
> > > And the persistence xml...
> > >
> > > http://java.sun.com/xml/ns/persistence";
> > >  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > >  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> > > http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd";
> > >  version="2.0">
> > >  
> > >
> > >
> org.apache.openjpa.persistence.PersistenceProviderImpl
> > >
> > >
> > >
> > >com.spidertracks.aviator.model.Persistable
> > >com.spidertracks.aviator.model.UuidEntity
> > >
> > >
> > >
> > >com.spidertracks.aviator.model.cluster.ClusterRegion
> > >com.spidertracks.aviator.model.cluster.SpiderRegion
> > >
> > >
> > >
> > >
> > >
> com.spidertracks.aviator.model.security.AviatorRememberMeToken
> > >
> > >
> > >
>  com.spidertracks.aviator.model.sms.PhoneValidationMessage
> > >com.spidertracks.aviator.model.sms.ReceivedSmsMessage
> > >com.spidertracks.aviator.model.sms.SentSmsMessage
> > >com.spidertracks.aviator.model.sms.SmsMessage
> > >com.spidertracks.aviator.model.sms.SosClosedMessage
> > >
> > >
> com.spidertracks.aviator.model.sms.SosInvalidResponseMessage
> > >com.spidertracks.aviator.model.sms.SosMessage
> > >com.spidertracks.aviator.model.sms.SosTierOneMessage
> > >
> > >
> > >
> com.spidertracks.aviator.model.sms.SosTierOneReopenedUserMessage
> > >com.spidertracks.aviator.model.sms.SosTierTwoMessage
> > >
> > >
> > >
> com.spidertracks.aviator.model.sms.SosTierTwoReopenedUserMessage
> > >
>  com.spidertracks.aviator.model.sms.SosTierTwoUserMessage
> > >
> > >
> > >
> > >com.spidertracks.aviator.model.sos.ContactedPerson
> > >com.spidertracks.aviator.model.sos.OpenHistory
> > >com.spidertracks.aviator.model.sos.SoS
> > >
> > >
> > >com.spidertracks.aviator.model.spider.Spider
> > >
> > >
> > >
> > >
> > >
> com.spidertracks.aviator.model.spider.message.AlertAcknowlege
> > >
> > >
> > >
> com.spidertracks.aviator.model.spider.message.ConfigMessageUpdate
> > >
> > >
> > >
> com.spidertracks.aviator.model.spider.message.DistanceSettings
> > >
> > >
> > >
> com.spidertracks.aviator.model.spider.message.MobileTerminatedConfirmation
> > >
> > >
> com.spidertracks.aviator.model.spider.message.SpiderUpdate
> > >
> > >
> > >
> com.spidertracks.aviator.model.spider.message.SpiderwatchSettings
> > >
> > >
> > >
> com.spidertracks.aviator.model.spider.message.TimeDistanceSettings
> > >
> > >
> com.spidertracks.aviator.model.spider.message.TimeSettings
> > >
>  com.spidertracks.aviator.model.spider.message.WatchOff
> > >com.spidertracks.aviator.model.spider.message.WatchOn
> > >
> > >
> > >
> > >com.spidertracks.aviator.model.user.ContactLink
> > >com.spidertracks.aviator.model.user.Address
> > >com.spidertracks.aviator.model.user.Customer
> > >
> > >
> com.spidertracks.aviator.model.user.EmailConfirmationToken
> > >com.spidertracks.aviator.model.user.HashedUserToken
> > >com.spidertracks.aviator.model.user.InvitedPerson
> > >
>  com.spidertracks.aviator.model.user.PasswordResetToken
> > >com.spidertracks.aviator.model.user.Person
> > >com.spide

Re: Audit log with OpenJPA

2011-07-12 Thread Jim Talbut

On 12/07/2011 09:33, Bengt Rodehav wrote:

Why do you think that your approach is not supported by JPA? From other
posts on this list I've seen that you are allowed to add/enrich your entity
in the PreUpdate/PreCreate callbacks. That's all you are doing right. Then
JPA persists your enriched entities.


I asked on this list a few months ago:
http://web.archiveorange.com/archive/v/tXrrxw9bXkttUykS7B6K

You can change the state of entities, but creating new entities is not 
permitted by the JPA spec.
At the moment it does work, and I now what I'm going to do if it stops 
working, so I'm happy.
I'd be happier if OpenJPA explicitly supported it, but it doesn't keep 
me awake at night.


Jim


Re: Audit log with OpenJPA

2011-07-12 Thread Bengt Rodehav
Jim,

Why do you think that your approach is not supported by JPA? From other
posts on this list I've seen that you are allowed to add/enrich your entity
in the PreUpdate/PreCreate callbacks. That's all you are doing right. Then
JPA persists your enriched entities.

What do you violate?

/Bengt

2011/7/12 Jim Talbut 

> On 12/07/2011 08:49, Bengt Rodehav wrote:
>
>> Your other design decision is also interesting. By having a relationship
>> to
>> the audit log entries JPA will persist the audit log entry for you - very
>> convenient indeed. A little similar to the way Pinaki described
>> previously.
>> However you store the audit log in a separate table while Pinaki stores
>> the
>> audit log together with the entity (in a separate column) that is being
>> persisted. I kind of like your approach better. I think an audit log can
>> be
>> viewed from two different angles: the entity view and the user view. You
>> need to be able to see what changes have been made to an entity and
>> possibly
>> even implment undo (like Pinaki). However, you also need to be able to
>> track
>> all changes done by a specific user during a specific time period. The
>> latter is much easier with a centralized place for all audit log entries.
>> Can't really see how that can easily be done with Pinaki's approach.
>>
> With the specifics of my implementation undo would be very awkward to
> implement, but that's because I'm trying to produce a textual change
> tracking log rather than an undo per-se.
> I could modify my layout to support undo, but it would still be more
> complex than a model that put the undo records in the original table.
>
>  The only thing I might miss from your solution then is the ability to
>> configure whether audit logging is enabled for an entity or not. Our
>> customers have different requirements here. But then again, this should be
>> possible in your approach as well. In the @PreUpdate method I could check
>> (somehow) if audit logging is enabled for this entity. If yes, then create
>> the audit log entry and add it to the collection. If not, then don't
>> create
>> the audit log entry and nothing will be logged - right?
>>
> That's right.
> For my purposes I don't want to exclude any entities of a given type - so
> three different (unrelated) entity classes perform auditing but there is no
> filtering of entities of an audited type.
>
>  Have you had the need to configure OpenJPA in some specific way for
>> performance reasons? I guess you really want to avoid OpenJPA fetching all
>> your audit log entries every time an entity is fetched...
>>
> All I've done is make the audit entries lazy-fetch and I believe that works
> (though honestly I haven't actually tested it).
>
>  Also, I need to know whether this is a supported JPA/OpenJPA way of doing
>> things. My guess is yes since you don't actually use the entity manager
>> yourself.
>>
> It's not, that's the big downside.
> The only way you're going to get an official approach is with a JDBC call
> in the same transaction (which I ditched because of the difficulties of
> getting hold of the transactional context and other things from within the
> listener).
> If I find that the approach fails in a future version of OpenJPA I'll
> switch to JDBC, by having the entities in a separate table this is quite a
> clean swap and the only difficulty is getting the necessary context
> available at the right place.
>
> Jim
>


Re: Audit log with OpenJPA

2011-07-12 Thread Jim Talbut

On 12/07/2011 08:49, Bengt Rodehav wrote:

Your other design decision is also interesting. By having a relationship to
the audit log entries JPA will persist the audit log entry for you - very
convenient indeed. A little similar to the way Pinaki described previously.
However you store the audit log in a separate table while Pinaki stores the
audit log together with the entity (in a separate column) that is being
persisted. I kind of like your approach better. I think an audit log can be
viewed from two different angles: the entity view and the user view. You
need to be able to see what changes have been made to an entity and possibly
even implment undo (like Pinaki). However, you also need to be able to track
all changes done by a specific user during a specific time period. The
latter is much easier with a centralized place for all audit log entries.
Can't really see how that can easily be done with Pinaki's approach.
With the specifics of my implementation undo would be very awkward to 
implement, but that's because I'm trying to produce a textual change 
tracking log rather than an undo per-se.
I could modify my layout to support undo, but it would still be more 
complex than a model that put the undo records in the original table.

The only thing I might miss from your solution then is the ability to
configure whether audit logging is enabled for an entity or not. Our
customers have different requirements here. But then again, this should be
possible in your approach as well. In the @PreUpdate method I could check
(somehow) if audit logging is enabled for this entity. If yes, then create
the audit log entry and add it to the collection. If not, then don't create
the audit log entry and nothing will be logged - right?

That's right.
For my purposes I don't want to exclude any entities of a given type - 
so three different (unrelated) entity classes perform auditing but there 
is no filtering of entities of an audited type.

Have you had the need to configure OpenJPA in some specific way for
performance reasons? I guess you really want to avoid OpenJPA fetching all
your audit log entries every time an entity is fetched...
All I've done is make the audit entries lazy-fetch and I believe that 
works (though honestly I haven't actually tested it).

Also, I need to know whether this is a supported JPA/OpenJPA way of doing
things. My guess is yes since you don't actually use the entity manager
yourself.

It's not, that's the big downside.
The only way you're going to get an official approach is with a JDBC 
call in the same transaction (which I ditched because of the 
difficulties of getting hold of the transactional context and other 
things from within the listener).
If I find that the approach fails in a future version of OpenJPA I'll 
switch to JDBC, by having the entities in a separate table this is quite 
a clean swap and the only difficulty is getting the necessary context 
available at the right place.


Jim


Re: Audit log with OpenJPA

2011-07-12 Thread Bengt Rodehav
Thanks for your post Jim,

In the past (when we rolled our own O/R mapping) we also generated the id's
ourselves via sequences stored in a dedicated table. Come to think of it,
one of the reasons was exactly what you are talking about - one can
reference the id even before the object is persisted. This is of course a
big benefit when it comes to audit logging (and actually other types of
logging as well). I will definitely revisit that.

Your other design decision is also interesting. By having a relationship to
the audit log entries JPA will persist the audit log entry for you - very
convenient indeed. A little similar to the way Pinaki described previously.
However you store the audit log in a separate table while Pinaki stores the
audit log together with the entity (in a separate column) that is being
persisted. I kind of like your approach better. I think an audit log can be
viewed from two different angles: the entity view and the user view. You
need to be able to see what changes have been made to an entity and possibly
even implment undo (like Pinaki). However, you also need to be able to track
all changes done by a specific user during a specific time period. The
latter is much easier with a centralized place for all audit log entries.
Can't really see how that can easily be done with Pinaki's approach.

The only thing I might miss from your solution then is the ability to
configure whether audit logging is enabled for an entity or not. Our
customers have different requirements here. But then again, this should be
possible in your approach as well. In the @PreUpdate method I could check
(somehow) if audit logging is enabled for this entity. If yes, then create
the audit log entry and add it to the collection. If not, then don't create
the audit log entry and nothing will be logged - right?

Have you had the need to configure OpenJPA in some specific way for
performance reasons? I guess you really want to avoid OpenJPA fetching all
your audit log entries every time an entity is fetched...

Also, I need to know whether this is a supported JPA/OpenJPA way of doing
things. My guess is yes since you don't actually use the entity manager
yourself.

Very interesting approach.

Thanks,

/Bengt



2011/7/12 Jim Talbut 

> On 07/07/2011 12:05, Bengt Rodehav wrote:
>
>> 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.
>>
> A bit late to the party, but this is what I've got working:
>
> Change the entity ID column so it's not allocated by the database, then it
> becomes valid from the time the entity is persisted, rather than the time
> it's flushed.
> By using a table type sequence generator the disadvantages relative to a
> database generated ID are few (and IME are only seen if you are abusing the
> IDs :) )
>
> I only carry out an audit in @PreUpdate, because all I track is changes and
> there aren't any changes for a new record - so actually the ID generation
> should be irrelevant.
> But by working in PreUpdate I've found that I am able to work with the
> entity manager and create new entities for the audit.
>
> The entity being audited has a OneToMany join to the audit entries, so I
> don't have to call persist on the audit log object, I just add it to the
> collection in the entity being audited.
>
> Jim
>
>