You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jim O'Callaghan <jc...@yahoo.co.uk> on 2009/12/17 22:43:46 UTC

Tapestry5 and envers

Has anyone got envers (http://www.jboss.org/files/envers/docs/index.html) running with Tapestry5/hibernate and care to share their configuration notes?  I'm trying:

<hibernate-configuration>
<session-factory>
...
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-insert"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-update"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-delete"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="pre-collection-update"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="pre-collection-remove"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-collection-recreate"/>
...
</session-factory>
</hibernate-configuration>

having previously tried:

		<property name="eventListeners">
		   <map>       
		   <entry key="post-insert"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   <entry key="post-update"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   <entry key="post-delete"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   <entry key="pre-collection-update"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   <entry key="pre-collection-remove"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   <entry key="post-collection-recreate"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   </map>
		</property>

and variants, but end up with the same NPE at sessionfactory init:

Caused by: java.lang.NullPointerException
	at org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader.addPropertiesFromClass(AuditedPropertiesReader.java:90)
	at org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader.read(AuditedPropertiesReader.java:73)
	at org.hibernate.envers.configuration.metadata.reader.AnnotationsMetadataReader.getAuditData(AnnotationsMetadataReader.java:120)
	at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:77)
	at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:86)
	at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:99)
	at org.hibernate.envers.event.AuditEventListener.initialize(AuditEventListener.java:260)
	at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
	at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
	at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
	... 120 more

This happens whether I annotate any of my entities with @audited or not.  Would be grateful for any pointers/gotchas, indications that envers does play nice with Tapestry5, or even any alternative generic entity auditing facility (not trigger based) that someone could recommend - thanks.

Regards,
Jim.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Tapestry5 and envers (2)

Posted by Jim O'Callaghan <jc...@yahoo.co.uk>.
Alejandro,

I got this working - thanks for your help.  There was an issue to do with Super/sub classes not being annotated with @Audited that contributed to the problem, which clouded the testing once the configuration had been sorted out - thanks.

Regards,
Jim.

-----Original Message-----
From: Jim O'Callaghan [mailto:jc1000001@yahoo.co.uk]
Sent: 21 December 2009 10:22
To: Tapestry users
Subject: RE: Tapestry5 and envers (2)


Hi Alejandro,

Your email is encouraging in that it confirms envers can be used successfully with Tapestry, though unfortunately I am already using context class 'thread' and the non-proxy hibernate session so must start looking elsewhere for the source of the problem.  Can you tell me what version of Tapestry you are using (I am on 5.1.0.5) and whether you are using the Tapestry-Hibernate package or integrating Hibernate yourself?  Also, does your getClassDescriptor().getType() method below return a <entity>.class or a <entity>_AUD.class - i.e. have you any non-dynamic representations of the *_AUD classes in your application or is envers doing all the work at runtime?  Thanks.

Regards,
Jim.

-----Original Message-----
From: Alejandro Scandroli [mailto:alejandroscandroli@gmail.com]
Sent: 20 December 2009 16:46
To: Tapestry users
Subject: Re: Tapestry5 and envers (2)


Hi Jim

> Are you able to query the audited entities using the AuditReader?
Yes, I can create queries using AuditReader.

Two questions:
1) Are you using current_session_context_class = thread ?
		<property name="current_session_context_class">thread</property>

2) Are you using the "real" Hibernate Session.
http://www.mail-archive.com/users@tapestry.apache.org/msg37227.html

Here is my code (the relevant part)

	@Inject
	private HibernateSessionManager sessionManager;
.....

AuditReader reader = AuditReaderFactory.get(sessionManager.getSession());
AuditQuery query =
reader.createQuery().forRevisionsOfEntity(getClassDescriptor().getType(),
false, true);

query.add(AuditEntity.id().eq(getBeanId()));


Saludos.
Alejandro.

On Sun, Dec 20, 2009 at 2:59 PM, Jim O'Callaghan <jc...@yahoo.co.uk> wrote:
> Howard, Alejandro,
>
> Thanks for looking at the problem.
>
> Alejandro,
>
> Thanks for the detailed source.
>
> I had made local (less elegant!) changes that I think have the same net effect as the changes you have outlined below:
>
>  - locally modified org.apache.tapestry5.hibernate.HibernateModule.java to not contribute a ValueEncoder for a persistentClass if the class has no MappedClass (I was using .hasPojoRepresentation to decide as I wasn't sure that the lack of a MappedClass should be correctly flagged as an error situation under certain circumstances)
>
>  - added a section as follows to the existing contributeHibernateSessionSource method within my AppModule:
>
>                            AuditEventListener[] auditEventListener = new AuditEventListener[] {new AuditEventListener()};
>                            configuration.getEventListeners().setPostInsertEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPostUpdateEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPostDeleteEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPreCollectionUpdateEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPreCollectionRemoveEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPostCollectionRecreateEventListeners(auditEventListener);
>
> The type of AuditEventListener above is definitely org.hibernate.envers.event.AuditEventListener.  My entities are being audited correctly upon save / update - the problem is when I use org.hibernate.envers.AuditReaderFactory / AuditReader to create a query to return some of the audited entities - this is where the "xyz_AUD is not mapped" issue occurs.  Are you able to query the audited entities using the AuditReader?  If you are then perhaps I have some other settings incorrect - I also tried taking out my changes and replacing them with yours, in case there was some subtle difference I was missing, but got the same result. Thanks.
>
> Regards,
> Jim.
>
> -----Original Message-----
> From: Alejandro Scandroli [mailto:alejandroscandroli@gmail.com]
> Sent: 19 December 2009 20:05
> To: Tapestry users
> Subject: Re: Tapestry5 and envers (2)
>
>
> Here is how I worked around this problem:
>
> First in your AppModule prevent Hibernate from contributing the
> ValueEncoderSource with this:
>
> public static void
> contributeFactoryDefaults(MappedConfiguration<String, String>
> configuration)
> {
>    configuration.override(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS,
> "false");
> }
>
> Then implement your own contributeValueEncoderSource skipping the
> ValueEncoder creation if entityClass is null
>
> @SuppressWarnings("unchecked")
> public static void
> contributeValueEncoderSource(MappedConfiguration<Class,
> ValueEncoderFactory> configuration,
>                                                final
> HibernateSessionSource sessionSource,
>                                                final Session session,
>                                                final TypeCoercer typeCoercer,
>                                                final PropertyAccess
> propertyAccess,
>                                                final LoggerSource loggerSource)
> {
>
>    org.hibernate.cfg.Configuration config = sessionSource.getConfiguration();
>    Iterator<PersistentClass> mappings = config.getClassMappings();
>    while (mappings.hasNext())
>    {
>        final PersistentClass persistentClass = mappings.next();
>        final Class entityClass = persistentClass.getMappedClass();
>
>        if (entityClass != null)
>        {
>            ValueEncoderFactory factory = new ValueEncoderFactory()
>            {
>                public ValueEncoder create(Class type)
>                {
>                    return new
> HibernateEntityValueEncoder(entityClass, persistentClass, session,
> propertyAccess,
>                            typeCoercer, loggerSource.getLogger(entityClass));
>                }
>            };
>
>            configuration.add(entityClass, factory);
>        }
>    }
> }
>
>
> That's it.
>
> Now that I know it's not just me, I will file a JIRA issue for adding
> the check "if (entityClass != null)" to the main tapestry-hibernate
> module.
>
> Bonus track:
>
> I also use an HibernateConfigurer for adding the Listeners
>
> public class EnversHibernateConfigurer implements HibernateConfigurer
> {
>
>        public EnversHibernateConfigurer() {}
>
>        public void configure(Configuration configuration)
>        {
>                configuration.setListener("post-insert",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("post-update",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("post-delete",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("pre-collection-update",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("pre-collection-remove",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("post-collection-recreate",
> "org.hibernate.envers.event.AuditEventListener");
>        }
> }
>
>
> I planned to release this code to open source in January, but if you
> are willing to try untested code I can check it in sooner.
>
> I hope it helps.
>
> Saludos.
> Alejandro Scandroli.
>
> On Sat, Dec 19, 2009 at 1:32 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
>> I'm afraid I'm not familiar enough with envers to help ... I haven't
>> heard of it before.
>>
>> On Fri, Dec 18, 2009 at 4:21 PM, Jim O'Callaghan <jc...@yahoo.co.uk> wrote:
>>> Still stumped on this - any pointers on where to look or Tapestry5 relevant examples would be really helpful.
>>>
>>> Relevant envers listeners are configured and are working correctly when entities are created / updated.  Tapestry (specifically the hibernate session) does not appear to see the generated xyz_AUD entities and complains that these entities are not mapped with an error ex.:
>>>
>>> Caused by: org.hibernate.hql.ast.QuerySyntaxException: com.abc.xyz.entities.core.user.User_AUD is not mapped [select e, r from ...
>>>
>>> ... whenever any AuditReader methods are called.
>>>
>>> Within method contributeValueEncoderSource in HibernateModule.java, persistentClass.getMappedClass() returns null for the *_AUD classes, resulting in an error adding the entity to the configuration (blank key).  I tried testing classForName on the *_AUD entities where .hasPojoRepresentation returns false but get class not found exception.
>>>
>>> Towards the end of startup output I do see the entities I expect configured:
>>>
>>> [INFO] HibernateCoreModule.HibernateSessionSource Configured Hibernate entities: Client_Address_AUD, Client_Phone_AUD, com.abc.xyz.entities.core.SystemKey, com.abc.xyz.entities.core.client.Address, com.abc.xyz.entities.core.client.Address_AUD, com.abc.xyz.entities.core.client.Client, com.abc.xyz.entities.core.client.Client_AUD, com.abc.xyz.entities.core.client.Phone, com.abc.xyz.entities.core.client.Phone_AUD, com.abc.xyz.entities.core.user.Role, com.abc.xyz.entities.core.user.User, com.abc.xyz.entities.core.user.UserClass, com.abc.xyz.entities.menu.Menu, com.abc.xyz.entities.menu.MenuEntry, org.hibernate.envers.DefaultRevisionEntity
>>>
>>> The earlier startup output does differ between the concrete entities and the envers ones:
>>>
>>> .
>>> .
>>> .
>>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Client
>>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Client on table Client
>>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Address
>>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Address on table Address
>>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Phone
>>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Phone on table Phone
>>> .
>>> .
>>> .
>>>
>>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Client_AUD -> Client_AUD
>>> [INFO] cfg.HbmBinder Mapping class: Client_Address_AUD -> Client_Address_AUD
>>> [INFO] cfg.HbmBinder Mapping class: Client_Phone_AUD -> Client_Phone_AUD
>>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Address_AUD -> Address_AUD
>>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Phone_AUD -> Phone_AUD
>>> [INFO] cfg.HbmBinder Mapping class: org.hibernate.envers.DefaultRevisionEntity -> REVINFO
>>>
>>> Does this give any clues - HbmBinder vs. EntityBinder?
>>>
>>> Regards,
>>> Jim.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>>
>> The source for Tapestry training, mentoring and support. Contact me to
>> learn how I can get you up and productive in Tapestry fast!
>>
>> (971) 678-5210
>> http://howardlewisship.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Tapestry5 and envers (2)

Posted by Jim O'Callaghan <jc...@yahoo.co.uk>.
Hi Alejandro,

Your email is encouraging in that it confirms envers can be used successfully with Tapestry, though unfortunately I am already using context class 'thread' and the non-proxy hibernate session so must start looking elsewhere for the source of the problem.  Can you tell me what version of Tapestry you are using (I am on 5.1.0.5) and whether you are using the Tapestry-Hibernate package or integrating Hibernate yourself?  Also, does your getClassDescriptor().getType() method below return a <entity>.class or a <entity>_AUD.class - i.e. have you any non-dynamic representations of the *_AUD classes in your application or is envers doing all the work at runtime?  Thanks.

Regards,
Jim.

-----Original Message-----
From: Alejandro Scandroli [mailto:alejandroscandroli@gmail.com]
Sent: 20 December 2009 16:46
To: Tapestry users
Subject: Re: Tapestry5 and envers (2)


Hi Jim

> Are you able to query the audited entities using the AuditReader?
Yes, I can create queries using AuditReader.

Two questions:
1) Are you using current_session_context_class = thread ?
		<property name="current_session_context_class">thread</property>

2) Are you using the "real" Hibernate Session.
http://www.mail-archive.com/users@tapestry.apache.org/msg37227.html

Here is my code (the relevant part)

	@Inject
	private HibernateSessionManager sessionManager;
.....

AuditReader reader = AuditReaderFactory.get(sessionManager.getSession());
AuditQuery query =
reader.createQuery().forRevisionsOfEntity(getClassDescriptor().getType(),
false, true);

query.add(AuditEntity.id().eq(getBeanId()));


Saludos.
Alejandro.

On Sun, Dec 20, 2009 at 2:59 PM, Jim O'Callaghan <jc...@yahoo.co.uk> wrote:
> Howard, Alejandro,
>
> Thanks for looking at the problem.
>
> Alejandro,
>
> Thanks for the detailed source.
>
> I had made local (less elegant!) changes that I think have the same net effect as the changes you have outlined below:
>
>  - locally modified org.apache.tapestry5.hibernate.HibernateModule.java to not contribute a ValueEncoder for a persistentClass if the class has no MappedClass (I was using .hasPojoRepresentation to decide as I wasn't sure that the lack of a MappedClass should be correctly flagged as an error situation under certain circumstances)
>
>  - added a section as follows to the existing contributeHibernateSessionSource method within my AppModule:
>
>                            AuditEventListener[] auditEventListener = new AuditEventListener[] {new AuditEventListener()};
>                            configuration.getEventListeners().setPostInsertEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPostUpdateEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPostDeleteEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPreCollectionUpdateEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPreCollectionRemoveEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPostCollectionRecreateEventListeners(auditEventListener);
>
> The type of AuditEventListener above is definitely org.hibernate.envers.event.AuditEventListener.  My entities are being audited correctly upon save / update - the problem is when I use org.hibernate.envers.AuditReaderFactory / AuditReader to create a query to return some of the audited entities - this is where the "xyz_AUD is not mapped" issue occurs.  Are you able to query the audited entities using the AuditReader?  If you are then perhaps I have some other settings incorrect - I also tried taking out my changes and replacing them with yours, in case there was some subtle difference I was missing, but got the same result. Thanks.
>
> Regards,
> Jim.
>
> -----Original Message-----
> From: Alejandro Scandroli [mailto:alejandroscandroli@gmail.com]
> Sent: 19 December 2009 20:05
> To: Tapestry users
> Subject: Re: Tapestry5 and envers (2)
>
>
> Here is how I worked around this problem:
>
> First in your AppModule prevent Hibernate from contributing the
> ValueEncoderSource with this:
>
> public static void
> contributeFactoryDefaults(MappedConfiguration<String, String>
> configuration)
> {
>    configuration.override(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS,
> "false");
> }
>
> Then implement your own contributeValueEncoderSource skipping the
> ValueEncoder creation if entityClass is null
>
> @SuppressWarnings("unchecked")
> public static void
> contributeValueEncoderSource(MappedConfiguration<Class,
> ValueEncoderFactory> configuration,
>                                                final
> HibernateSessionSource sessionSource,
>                                                final Session session,
>                                                final TypeCoercer typeCoercer,
>                                                final PropertyAccess
> propertyAccess,
>                                                final LoggerSource loggerSource)
> {
>
>    org.hibernate.cfg.Configuration config = sessionSource.getConfiguration();
>    Iterator<PersistentClass> mappings = config.getClassMappings();
>    while (mappings.hasNext())
>    {
>        final PersistentClass persistentClass = mappings.next();
>        final Class entityClass = persistentClass.getMappedClass();
>
>        if (entityClass != null)
>        {
>            ValueEncoderFactory factory = new ValueEncoderFactory()
>            {
>                public ValueEncoder create(Class type)
>                {
>                    return new
> HibernateEntityValueEncoder(entityClass, persistentClass, session,
> propertyAccess,
>                            typeCoercer, loggerSource.getLogger(entityClass));
>                }
>            };
>
>            configuration.add(entityClass, factory);
>        }
>    }
> }
>
>
> That's it.
>
> Now that I know it's not just me, I will file a JIRA issue for adding
> the check "if (entityClass != null)" to the main tapestry-hibernate
> module.
>
> Bonus track:
>
> I also use an HibernateConfigurer for adding the Listeners
>
> public class EnversHibernateConfigurer implements HibernateConfigurer
> {
>
>        public EnversHibernateConfigurer() {}
>
>        public void configure(Configuration configuration)
>        {
>                configuration.setListener("post-insert",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("post-update",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("post-delete",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("pre-collection-update",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("pre-collection-remove",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("post-collection-recreate",
> "org.hibernate.envers.event.AuditEventListener");
>        }
> }
>
>
> I planned to release this code to open source in January, but if you
> are willing to try untested code I can check it in sooner.
>
> I hope it helps.
>
> Saludos.
> Alejandro Scandroli.
>
> On Sat, Dec 19, 2009 at 1:32 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
>> I'm afraid I'm not familiar enough with envers to help ... I haven't
>> heard of it before.
>>
>> On Fri, Dec 18, 2009 at 4:21 PM, Jim O'Callaghan <jc...@yahoo.co.uk> wrote:
>>> Still stumped on this - any pointers on where to look or Tapestry5 relevant examples would be really helpful.
>>>
>>> Relevant envers listeners are configured and are working correctly when entities are created / updated.  Tapestry (specifically the hibernate session) does not appear to see the generated xyz_AUD entities and complains that these entities are not mapped with an error ex.:
>>>
>>> Caused by: org.hibernate.hql.ast.QuerySyntaxException: com.abc.xyz.entities.core.user.User_AUD is not mapped [select e, r from ...
>>>
>>> ... whenever any AuditReader methods are called.
>>>
>>> Within method contributeValueEncoderSource in HibernateModule.java, persistentClass.getMappedClass() returns null for the *_AUD classes, resulting in an error adding the entity to the configuration (blank key).  I tried testing classForName on the *_AUD entities where .hasPojoRepresentation returns false but get class not found exception.
>>>
>>> Towards the end of startup output I do see the entities I expect configured:
>>>
>>> [INFO] HibernateCoreModule.HibernateSessionSource Configured Hibernate entities: Client_Address_AUD, Client_Phone_AUD, com.abc.xyz.entities.core.SystemKey, com.abc.xyz.entities.core.client.Address, com.abc.xyz.entities.core.client.Address_AUD, com.abc.xyz.entities.core.client.Client, com.abc.xyz.entities.core.client.Client_AUD, com.abc.xyz.entities.core.client.Phone, com.abc.xyz.entities.core.client.Phone_AUD, com.abc.xyz.entities.core.user.Role, com.abc.xyz.entities.core.user.User, com.abc.xyz.entities.core.user.UserClass, com.abc.xyz.entities.menu.Menu, com.abc.xyz.entities.menu.MenuEntry, org.hibernate.envers.DefaultRevisionEntity
>>>
>>> The earlier startup output does differ between the concrete entities and the envers ones:
>>>
>>> .
>>> .
>>> .
>>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Client
>>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Client on table Client
>>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Address
>>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Address on table Address
>>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Phone
>>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Phone on table Phone
>>> .
>>> .
>>> .
>>>
>>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Client_AUD -> Client_AUD
>>> [INFO] cfg.HbmBinder Mapping class: Client_Address_AUD -> Client_Address_AUD
>>> [INFO] cfg.HbmBinder Mapping class: Client_Phone_AUD -> Client_Phone_AUD
>>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Address_AUD -> Address_AUD
>>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Phone_AUD -> Phone_AUD
>>> [INFO] cfg.HbmBinder Mapping class: org.hibernate.envers.DefaultRevisionEntity -> REVINFO
>>>
>>> Does this give any clues - HbmBinder vs. EntityBinder?
>>>
>>> Regards,
>>> Jim.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>>
>> The source for Tapestry training, mentoring and support. Contact me to
>> learn how I can get you up and productive in Tapestry fast!
>>
>> (971) 678-5210
>> http://howardlewisship.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Tapestry5 and envers (2)

Posted by Alejandro Scandroli <al...@gmail.com>.
Hi Jim

> Are you able to query the audited entities using the AuditReader?
Yes, I can create queries using AuditReader.

Two questions:
1) Are you using current_session_context_class = thread ?
		<property name="current_session_context_class">thread</property>

2) Are you using the "real" Hibernate Session.
http://www.mail-archive.com/users@tapestry.apache.org/msg37227.html

Here is my code (the relevant part)

	@Inject
	private HibernateSessionManager sessionManager;
.....

AuditReader reader = AuditReaderFactory.get(sessionManager.getSession());
AuditQuery query =
reader.createQuery().forRevisionsOfEntity(getClassDescriptor().getType(),
false, true);

query.add(AuditEntity.id().eq(getBeanId()));


Saludos.
Alejandro.

On Sun, Dec 20, 2009 at 2:59 PM, Jim O'Callaghan <jc...@yahoo.co.uk> wrote:
> Howard, Alejandro,
>
> Thanks for looking at the problem.
>
> Alejandro,
>
> Thanks for the detailed source.
>
> I had made local (less elegant!) changes that I think have the same net effect as the changes you have outlined below:
>
>  - locally modified org.apache.tapestry5.hibernate.HibernateModule.java to not contribute a ValueEncoder for a persistentClass if the class has no MappedClass (I was using .hasPojoRepresentation to decide as I wasn't sure that the lack of a MappedClass should be correctly flagged as an error situation under certain circumstances)
>
>  - added a section as follows to the existing contributeHibernateSessionSource method within my AppModule:
>
>                            AuditEventListener[] auditEventListener = new AuditEventListener[] {new AuditEventListener()};
>                            configuration.getEventListeners().setPostInsertEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPostUpdateEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPostDeleteEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPreCollectionUpdateEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPreCollectionRemoveEventListeners(auditEventListener);
>                            configuration.getEventListeners().setPostCollectionRecreateEventListeners(auditEventListener);
>
> The type of AuditEventListener above is definitely org.hibernate.envers.event.AuditEventListener.  My entities are being audited correctly upon save / update - the problem is when I use org.hibernate.envers.AuditReaderFactory / AuditReader to create a query to return some of the audited entities - this is where the "xyz_AUD is not mapped" issue occurs.  Are you able to query the audited entities using the AuditReader?  If you are then perhaps I have some other settings incorrect - I also tried taking out my changes and replacing them with yours, in case there was some subtle difference I was missing, but got the same result. Thanks.
>
> Regards,
> Jim.
>
> -----Original Message-----
> From: Alejandro Scandroli [mailto:alejandroscandroli@gmail.com]
> Sent: 19 December 2009 20:05
> To: Tapestry users
> Subject: Re: Tapestry5 and envers (2)
>
>
> Here is how I worked around this problem:
>
> First in your AppModule prevent Hibernate from contributing the
> ValueEncoderSource with this:
>
> public static void
> contributeFactoryDefaults(MappedConfiguration<String, String>
> configuration)
> {
>    configuration.override(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS,
> "false");
> }
>
> Then implement your own contributeValueEncoderSource skipping the
> ValueEncoder creation if entityClass is null
>
> @SuppressWarnings("unchecked")
> public static void
> contributeValueEncoderSource(MappedConfiguration<Class,
> ValueEncoderFactory> configuration,
>                                                final
> HibernateSessionSource sessionSource,
>                                                final Session session,
>                                                final TypeCoercer typeCoercer,
>                                                final PropertyAccess
> propertyAccess,
>                                                final LoggerSource loggerSource)
> {
>
>    org.hibernate.cfg.Configuration config = sessionSource.getConfiguration();
>    Iterator<PersistentClass> mappings = config.getClassMappings();
>    while (mappings.hasNext())
>    {
>        final PersistentClass persistentClass = mappings.next();
>        final Class entityClass = persistentClass.getMappedClass();
>
>        if (entityClass != null)
>        {
>            ValueEncoderFactory factory = new ValueEncoderFactory()
>            {
>                public ValueEncoder create(Class type)
>                {
>                    return new
> HibernateEntityValueEncoder(entityClass, persistentClass, session,
> propertyAccess,
>                            typeCoercer, loggerSource.getLogger(entityClass));
>                }
>            };
>
>            configuration.add(entityClass, factory);
>        }
>    }
> }
>
>
> That's it.
>
> Now that I know it's not just me, I will file a JIRA issue for adding
> the check "if (entityClass != null)" to the main tapestry-hibernate
> module.
>
> Bonus track:
>
> I also use an HibernateConfigurer for adding the Listeners
>
> public class EnversHibernateConfigurer implements HibernateConfigurer
> {
>
>        public EnversHibernateConfigurer() {}
>
>        public void configure(Configuration configuration)
>        {
>                configuration.setListener("post-insert",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("post-update",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("post-delete",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("pre-collection-update",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("pre-collection-remove",
> "org.hibernate.envers.event.AuditEventListener");
>                configuration.setListener("post-collection-recreate",
> "org.hibernate.envers.event.AuditEventListener");
>        }
> }
>
>
> I planned to release this code to open source in January, but if you
> are willing to try untested code I can check it in sooner.
>
> I hope it helps.
>
> Saludos.
> Alejandro Scandroli.
>
> On Sat, Dec 19, 2009 at 1:32 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
>> I'm afraid I'm not familiar enough with envers to help ... I haven't
>> heard of it before.
>>
>> On Fri, Dec 18, 2009 at 4:21 PM, Jim O'Callaghan <jc...@yahoo.co.uk> wrote:
>>> Still stumped on this - any pointers on where to look or Tapestry5 relevant examples would be really helpful.
>>>
>>> Relevant envers listeners are configured and are working correctly when entities are created / updated.  Tapestry (specifically the hibernate session) does not appear to see the generated xyz_AUD entities and complains that these entities are not mapped with an error ex.:
>>>
>>> Caused by: org.hibernate.hql.ast.QuerySyntaxException: com.abc.xyz.entities.core.user.User_AUD is not mapped [select e, r from ...
>>>
>>> ... whenever any AuditReader methods are called.
>>>
>>> Within method contributeValueEncoderSource in HibernateModule.java, persistentClass.getMappedClass() returns null for the *_AUD classes, resulting in an error adding the entity to the configuration (blank key).  I tried testing classForName on the *_AUD entities where .hasPojoRepresentation returns false but get class not found exception.
>>>
>>> Towards the end of startup output I do see the entities I expect configured:
>>>
>>> [INFO] HibernateCoreModule.HibernateSessionSource Configured Hibernate entities: Client_Address_AUD, Client_Phone_AUD, com.abc.xyz.entities.core.SystemKey, com.abc.xyz.entities.core.client.Address, com.abc.xyz.entities.core.client.Address_AUD, com.abc.xyz.entities.core.client.Client, com.abc.xyz.entities.core.client.Client_AUD, com.abc.xyz.entities.core.client.Phone, com.abc.xyz.entities.core.client.Phone_AUD, com.abc.xyz.entities.core.user.Role, com.abc.xyz.entities.core.user.User, com.abc.xyz.entities.core.user.UserClass, com.abc.xyz.entities.menu.Menu, com.abc.xyz.entities.menu.MenuEntry, org.hibernate.envers.DefaultRevisionEntity
>>>
>>> The earlier startup output does differ between the concrete entities and the envers ones:
>>>
>>> .
>>> .
>>> .
>>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Client
>>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Client on table Client
>>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Address
>>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Address on table Address
>>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Phone
>>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Phone on table Phone
>>> .
>>> .
>>> .
>>>
>>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Client_AUD -> Client_AUD
>>> [INFO] cfg.HbmBinder Mapping class: Client_Address_AUD -> Client_Address_AUD
>>> [INFO] cfg.HbmBinder Mapping class: Client_Phone_AUD -> Client_Phone_AUD
>>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Address_AUD -> Address_AUD
>>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Phone_AUD -> Phone_AUD
>>> [INFO] cfg.HbmBinder Mapping class: org.hibernate.envers.DefaultRevisionEntity -> REVINFO
>>>
>>> Does this give any clues - HbmBinder vs. EntityBinder?
>>>
>>> Regards,
>>> Jim.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>>
>> The source for Tapestry training, mentoring and support. Contact me to
>> learn how I can get you up and productive in Tapestry fast!
>>
>> (971) 678-5210
>> http://howardlewisship.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Tapestry5 and envers (2)

Posted by Jim O'Callaghan <jc...@yahoo.co.uk>.
Howard, Alejandro,

Thanks for looking at the problem.

Alejandro,

Thanks for the detailed source.

I had made local (less elegant!) changes that I think have the same net effect as the changes you have outlined below:

 - locally modified org.apache.tapestry5.hibernate.HibernateModule.java to not contribute a ValueEncoder for a persistentClass if the class has no MappedClass (I was using .hasPojoRepresentation to decide as I wasn't sure that the lack of a MappedClass should be correctly flagged as an error situation under certain circumstances)

 - added a section as follows to the existing contributeHibernateSessionSource method within my AppModule:

                            AuditEventListener[] auditEventListener = new AuditEventListener[] {new AuditEventListener()};
                            configuration.getEventListeners().setPostInsertEventListeners(auditEventListener);
                            configuration.getEventListeners().setPostUpdateEventListeners(auditEventListener);
                            configuration.getEventListeners().setPostDeleteEventListeners(auditEventListener);
                            configuration.getEventListeners().setPreCollectionUpdateEventListeners(auditEventListener);
                            configuration.getEventListeners().setPreCollectionRemoveEventListeners(auditEventListener);
                            configuration.getEventListeners().setPostCollectionRecreateEventListeners(auditEventListener);

The type of AuditEventListener above is definitely org.hibernate.envers.event.AuditEventListener.  My entities are being audited correctly upon save / update - the problem is when I use org.hibernate.envers.AuditReaderFactory / AuditReader to create a query to return some of the audited entities - this is where the "xyz_AUD is not mapped" issue occurs.  Are you able to query the audited entities using the AuditReader?  If you are then perhaps I have some other settings incorrect - I also tried taking out my changes and replacing them with yours, in case there was some subtle difference I was missing, but got the same result. Thanks.

Regards,
Jim.

-----Original Message-----
From: Alejandro Scandroli [mailto:alejandroscandroli@gmail.com]
Sent: 19 December 2009 20:05
To: Tapestry users
Subject: Re: Tapestry5 and envers (2)


Here is how I worked around this problem:

First in your AppModule prevent Hibernate from contributing the
ValueEncoderSource with this:

public static void
contributeFactoryDefaults(MappedConfiguration<String, String>
configuration)
{
    configuration.override(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS,
"false");
}

Then implement your own contributeValueEncoderSource skipping the
ValueEncoder creation if entityClass is null

@SuppressWarnings("unchecked")
public static void
contributeValueEncoderSource(MappedConfiguration<Class,
ValueEncoderFactory> configuration,
                                                final
HibernateSessionSource sessionSource,
                                                final Session session,
                                                final TypeCoercer typeCoercer,
                                                final PropertyAccess
propertyAccess,
                                                final LoggerSource loggerSource)
{

    org.hibernate.cfg.Configuration config = sessionSource.getConfiguration();
    Iterator<PersistentClass> mappings = config.getClassMappings();
    while (mappings.hasNext())
    {
        final PersistentClass persistentClass = mappings.next();
        final Class entityClass = persistentClass.getMappedClass();

        if (entityClass != null)
        {
            ValueEncoderFactory factory = new ValueEncoderFactory()
            {
                public ValueEncoder create(Class type)
                {
                    return new
HibernateEntityValueEncoder(entityClass, persistentClass, session,
propertyAccess,
                            typeCoercer, loggerSource.getLogger(entityClass));
                }
            };

            configuration.add(entityClass, factory);
        }
    }
}


That's it.

Now that I know it's not just me, I will file a JIRA issue for adding
the check "if (entityClass != null)" to the main tapestry-hibernate
module.

Bonus track:

I also use an HibernateConfigurer for adding the Listeners

public class EnversHibernateConfigurer implements HibernateConfigurer
{

	public EnversHibernateConfigurer() {}

	public void configure(Configuration configuration)
	{
		configuration.setListener("post-insert",
"org.hibernate.envers.event.AuditEventListener");
		configuration.setListener("post-update",
"org.hibernate.envers.event.AuditEventListener");
		configuration.setListener("post-delete",
"org.hibernate.envers.event.AuditEventListener");
		configuration.setListener("pre-collection-update",
"org.hibernate.envers.event.AuditEventListener");
		configuration.setListener("pre-collection-remove",
"org.hibernate.envers.event.AuditEventListener");
		configuration.setListener("post-collection-recreate",
"org.hibernate.envers.event.AuditEventListener");
	}
}


I planned to release this code to open source in January, but if you
are willing to try untested code I can check it in sooner.

I hope it helps.

Saludos.
Alejandro Scandroli.

On Sat, Dec 19, 2009 at 1:32 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
> I'm afraid I'm not familiar enough with envers to help ... I haven't
> heard of it before.
>
> On Fri, Dec 18, 2009 at 4:21 PM, Jim O'Callaghan <jc...@yahoo.co.uk> wrote:
>> Still stumped on this - any pointers on where to look or Tapestry5 relevant examples would be really helpful.
>>
>> Relevant envers listeners are configured and are working correctly when entities are created / updated.  Tapestry (specifically the hibernate session) does not appear to see the generated xyz_AUD entities and complains that these entities are not mapped with an error ex.:
>>
>> Caused by: org.hibernate.hql.ast.QuerySyntaxException: com.abc.xyz.entities.core.user.User_AUD is not mapped [select e, r from ...
>>
>> ... whenever any AuditReader methods are called.
>>
>> Within method contributeValueEncoderSource in HibernateModule.java, persistentClass.getMappedClass() returns null for the *_AUD classes, resulting in an error adding the entity to the configuration (blank key).  I tried testing classForName on the *_AUD entities where .hasPojoRepresentation returns false but get class not found exception.
>>
>> Towards the end of startup output I do see the entities I expect configured:
>>
>> [INFO] HibernateCoreModule.HibernateSessionSource Configured Hibernate entities: Client_Address_AUD, Client_Phone_AUD, com.abc.xyz.entities.core.SystemKey, com.abc.xyz.entities.core.client.Address, com.abc.xyz.entities.core.client.Address_AUD, com.abc.xyz.entities.core.client.Client, com.abc.xyz.entities.core.client.Client_AUD, com.abc.xyz.entities.core.client.Phone, com.abc.xyz.entities.core.client.Phone_AUD, com.abc.xyz.entities.core.user.Role, com.abc.xyz.entities.core.user.User, com.abc.xyz.entities.core.user.UserClass, com.abc.xyz.entities.menu.Menu, com.abc.xyz.entities.menu.MenuEntry, org.hibernate.envers.DefaultRevisionEntity
>>
>> The earlier startup output does differ between the concrete entities and the envers ones:
>>
>> .
>> .
>> .
>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Client
>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Client on table Client
>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Address
>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Address on table Address
>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Phone
>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Phone on table Phone
>> .
>> .
>> .
>>
>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Client_AUD -> Client_AUD
>> [INFO] cfg.HbmBinder Mapping class: Client_Address_AUD -> Client_Address_AUD
>> [INFO] cfg.HbmBinder Mapping class: Client_Phone_AUD -> Client_Phone_AUD
>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Address_AUD -> Address_AUD
>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Phone_AUD -> Phone_AUD
>> [INFO] cfg.HbmBinder Mapping class: org.hibernate.envers.DefaultRevisionEntity -> REVINFO
>>
>> Does this give any clues - HbmBinder vs. EntityBinder?
>>
>> Regards,
>> Jim.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Tapestry5 and envers (2)

Posted by Alejandro Scandroli <al...@gmail.com>.
Here is how I worked around this problem:

First in your AppModule prevent Hibernate from contributing the
ValueEncoderSource with this:

public static void
contributeFactoryDefaults(MappedConfiguration<String, String>
configuration)
{
    configuration.override(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS,
"false");
}

Then implement your own contributeValueEncoderSource skipping the
ValueEncoder creation if entityClass is null

@SuppressWarnings("unchecked")
public static void
contributeValueEncoderSource(MappedConfiguration<Class,
ValueEncoderFactory> configuration,
                                                final
HibernateSessionSource sessionSource,
                                                final Session session,
                                                final TypeCoercer typeCoercer,
                                                final PropertyAccess
propertyAccess,
                                                final LoggerSource loggerSource)
{

    org.hibernate.cfg.Configuration config = sessionSource.getConfiguration();
    Iterator<PersistentClass> mappings = config.getClassMappings();
    while (mappings.hasNext())
    {
        final PersistentClass persistentClass = mappings.next();
        final Class entityClass = persistentClass.getMappedClass();

        if (entityClass != null)
        {
            ValueEncoderFactory factory = new ValueEncoderFactory()
            {
                public ValueEncoder create(Class type)
                {
                    return new
HibernateEntityValueEncoder(entityClass, persistentClass, session,
propertyAccess,
                            typeCoercer, loggerSource.getLogger(entityClass));
                }
            };

            configuration.add(entityClass, factory);
        }
    }
}


That's it.

Now that I know it's not just me, I will file a JIRA issue for adding
the check "if (entityClass != null)" to the main tapestry-hibernate
module.

Bonus track:

I also use an HibernateConfigurer for adding the Listeners

public class EnversHibernateConfigurer implements HibernateConfigurer
{

	public EnversHibernateConfigurer() {}

	public void configure(Configuration configuration)
	{
		configuration.setListener("post-insert",
"org.hibernate.envers.event.AuditEventListener");
		configuration.setListener("post-update",
"org.hibernate.envers.event.AuditEventListener");
		configuration.setListener("post-delete",
"org.hibernate.envers.event.AuditEventListener");
		configuration.setListener("pre-collection-update",
"org.hibernate.envers.event.AuditEventListener");
		configuration.setListener("pre-collection-remove",
"org.hibernate.envers.event.AuditEventListener");
		configuration.setListener("post-collection-recreate",
"org.hibernate.envers.event.AuditEventListener");
	}
}


I planned to release this code to open source in January, but if you
are willing to try untested code I can check it in sooner.

I hope it helps.

Saludos.
Alejandro Scandroli.

On Sat, Dec 19, 2009 at 1:32 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
> I'm afraid I'm not familiar enough with envers to help ... I haven't
> heard of it before.
>
> On Fri, Dec 18, 2009 at 4:21 PM, Jim O'Callaghan <jc...@yahoo.co.uk> wrote:
>> Still stumped on this - any pointers on where to look or Tapestry5 relevant examples would be really helpful.
>>
>> Relevant envers listeners are configured and are working correctly when entities are created / updated.  Tapestry (specifically the hibernate session) does not appear to see the generated xyz_AUD entities and complains that these entities are not mapped with an error ex.:
>>
>> Caused by: org.hibernate.hql.ast.QuerySyntaxException: com.abc.xyz.entities.core.user.User_AUD is not mapped [select e, r from ...
>>
>> ... whenever any AuditReader methods are called.
>>
>> Within method contributeValueEncoderSource in HibernateModule.java, persistentClass.getMappedClass() returns null for the *_AUD classes, resulting in an error adding the entity to the configuration (blank key).  I tried testing classForName on the *_AUD entities where .hasPojoRepresentation returns false but get class not found exception.
>>
>> Towards the end of startup output I do see the entities I expect configured:
>>
>> [INFO] HibernateCoreModule.HibernateSessionSource Configured Hibernate entities: Client_Address_AUD, Client_Phone_AUD, com.abc.xyz.entities.core.SystemKey, com.abc.xyz.entities.core.client.Address, com.abc.xyz.entities.core.client.Address_AUD, com.abc.xyz.entities.core.client.Client, com.abc.xyz.entities.core.client.Client_AUD, com.abc.xyz.entities.core.client.Phone, com.abc.xyz.entities.core.client.Phone_AUD, com.abc.xyz.entities.core.user.Role, com.abc.xyz.entities.core.user.User, com.abc.xyz.entities.core.user.UserClass, com.abc.xyz.entities.menu.Menu, com.abc.xyz.entities.menu.MenuEntry, org.hibernate.envers.DefaultRevisionEntity
>>
>> The earlier startup output does differ between the concrete entities and the envers ones:
>>
>> .
>> .
>> .
>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Client
>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Client on table Client
>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Address
>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Address on table Address
>> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Phone
>> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Phone on table Phone
>> .
>> .
>> .
>>
>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Client_AUD -> Client_AUD
>> [INFO] cfg.HbmBinder Mapping class: Client_Address_AUD -> Client_Address_AUD
>> [INFO] cfg.HbmBinder Mapping class: Client_Phone_AUD -> Client_Phone_AUD
>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Address_AUD -> Address_AUD
>> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Phone_AUD -> Phone_AUD
>> [INFO] cfg.HbmBinder Mapping class: org.hibernate.envers.DefaultRevisionEntity -> REVINFO
>>
>> Does this give any clues - HbmBinder vs. EntityBinder?
>>
>> Regards,
>> Jim.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Tapestry5 and envers (2)

Posted by Howard Lewis Ship <hl...@gmail.com>.
I'm afraid I'm not familiar enough with envers to help ... I haven't
heard of it before.

On Fri, Dec 18, 2009 at 4:21 PM, Jim O'Callaghan <jc...@yahoo.co.uk> wrote:
> Still stumped on this - any pointers on where to look or Tapestry5 relevant examples would be really helpful.
>
> Relevant envers listeners are configured and are working correctly when entities are created / updated.  Tapestry (specifically the hibernate session) does not appear to see the generated xyz_AUD entities and complains that these entities are not mapped with an error ex.:
>
> Caused by: org.hibernate.hql.ast.QuerySyntaxException: com.abc.xyz.entities.core.user.User_AUD is not mapped [select e, r from ...
>
> ... whenever any AuditReader methods are called.
>
> Within method contributeValueEncoderSource in HibernateModule.java, persistentClass.getMappedClass() returns null for the *_AUD classes, resulting in an error adding the entity to the configuration (blank key).  I tried testing classForName on the *_AUD entities where .hasPojoRepresentation returns false but get class not found exception.
>
> Towards the end of startup output I do see the entities I expect configured:
>
> [INFO] HibernateCoreModule.HibernateSessionSource Configured Hibernate entities: Client_Address_AUD, Client_Phone_AUD, com.abc.xyz.entities.core.SystemKey, com.abc.xyz.entities.core.client.Address, com.abc.xyz.entities.core.client.Address_AUD, com.abc.xyz.entities.core.client.Client, com.abc.xyz.entities.core.client.Client_AUD, com.abc.xyz.entities.core.client.Phone, com.abc.xyz.entities.core.client.Phone_AUD, com.abc.xyz.entities.core.user.Role, com.abc.xyz.entities.core.user.User, com.abc.xyz.entities.core.user.UserClass, com.abc.xyz.entities.menu.Menu, com.abc.xyz.entities.menu.MenuEntry, org.hibernate.envers.DefaultRevisionEntity
>
> The earlier startup output does differ between the concrete entities and the envers ones:
>
> .
> .
> .
> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Client
> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Client on table Client
> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Address
> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Address on table Address
> [INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Phone
> [INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Phone on table Phone
> .
> .
> .
>
> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Client_AUD -> Client_AUD
> [INFO] cfg.HbmBinder Mapping class: Client_Address_AUD -> Client_Address_AUD
> [INFO] cfg.HbmBinder Mapping class: Client_Phone_AUD -> Client_Phone_AUD
> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Address_AUD -> Address_AUD
> [INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Phone_AUD -> Phone_AUD
> [INFO] cfg.HbmBinder Mapping class: org.hibernate.envers.DefaultRevisionEntity -> REVINFO
>
> Does this give any clues - HbmBinder vs. EntityBinder?
>
> Regards,
> Jim.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Tapestry5 and envers (2)

Posted by Jim O'Callaghan <jc...@yahoo.co.uk>.
Still stumped on this - any pointers on where to look or Tapestry5 relevant examples would be really helpful.

Relevant envers listeners are configured and are working correctly when entities are created / updated.  Tapestry (specifically the hibernate session) does not appear to see the generated xyz_AUD entities and complains that these entities are not mapped with an error ex.:

Caused by: org.hibernate.hql.ast.QuerySyntaxException: com.abc.xyz.entities.core.user.User_AUD is not mapped [select e, r from ...

... whenever any AuditReader methods are called.

Within method contributeValueEncoderSource in HibernateModule.java, persistentClass.getMappedClass() returns null for the *_AUD classes, resulting in an error adding the entity to the configuration (blank key).  I tried testing classForName on the *_AUD entities where .hasPojoRepresentation returns false but get class not found exception.

Towards the end of startup output I do see the entities I expect configured:

[INFO] HibernateCoreModule.HibernateSessionSource Configured Hibernate entities: Client_Address_AUD, Client_Phone_AUD, com.abc.xyz.entities.core.SystemKey, com.abc.xyz.entities.core.client.Address, com.abc.xyz.entities.core.client.Address_AUD, com.abc.xyz.entities.core.client.Client, com.abc.xyz.entities.core.client.Client_AUD, com.abc.xyz.entities.core.client.Phone, com.abc.xyz.entities.core.client.Phone_AUD, com.abc.xyz.entities.core.user.Role, com.abc.xyz.entities.core.user.User, com.abc.xyz.entities.core.user.UserClass, com.abc.xyz.entities.menu.Menu, com.abc.xyz.entities.menu.MenuEntry, org.hibernate.envers.DefaultRevisionEntity

The earlier startup output does differ between the concrete entities and the envers ones:

.
.
.
[INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Client
[INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Client on table Client
[INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Address
[INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Address on table Address
[INFO] cfg.AnnotationBinder Binding entity from annotated class: com.abc.xyz.entities.core.client.Phone
[INFO] annotations.EntityBinder Bind entity com.abc.xyz.entities.core.client.Phone on table Phone
.
.
.

[INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Client_AUD -> Client_AUD
[INFO] cfg.HbmBinder Mapping class: Client_Address_AUD -> Client_Address_AUD
[INFO] cfg.HbmBinder Mapping class: Client_Phone_AUD -> Client_Phone_AUD
[INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Address_AUD -> Address_AUD
[INFO] cfg.HbmBinder Mapping class: com.abc.xyz.entities.core.client.Phone_AUD -> Phone_AUD
[INFO] cfg.HbmBinder Mapping class: org.hibernate.envers.DefaultRevisionEntity -> REVINFO

Does this give any clues - HbmBinder vs. EntityBinder?

Regards,
Jim.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Tapestry5 and envers

Posted by Jim O'Callaghan <jc...@yahoo.co.uk>.
I resolved this and though I would share in case is of use to anyone:

line 113 in org.hibernate.envers.configuration.metadata.reader.AnnotationsMetadataReader:

XClass xclass = reflectionManager.classForName(pc.getClassName(), this.getClass());

throws a class not found exception when it tries to call classForName on an unused interface in the application that had been incorrectly annotated with @Entity - the relevant stack trace message had not been propagated correctly through the exception hierarchy.

Regards,
Jim.

-----Original Message-----
From: Jim O'Callaghan [mailto:jc1000001@yahoo.co.uk]
Sent: 17 December 2009 21:44
To: Tapestry users
Subject: Tapestry5 and envers


Has anyone got envers (http://www.jboss.org/files/envers/docs/index.html) running with Tapestry5/hibernate and care to share their configuration notes?  I'm trying:

<hibernate-configuration>
<session-factory>
...
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-insert"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-update"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-delete"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="pre-collection-update"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="pre-collection-remove"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-collection-recreate"/>
...
</session-factory>
</hibernate-configuration>

having previously tried:

		<property name="eventListeners">
		   <map>       
		   <entry key="post-insert"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   <entry key="post-update"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   <entry key="post-delete"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   <entry key="pre-collection-update"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   <entry key="pre-collection-remove"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   <entry key="post-collection-recreate"><bean class="org.hibernate.envers.event.AuditEventListener"/></entry>
		   </map>
		</property>

and variants, but end up with the same NPE at sessionfactory init:

Caused by: java.lang.NullPointerException
	at org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader.addPropertiesFromClass(AuditedPropertiesReader.java:90)
	at org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader.read(AuditedPropertiesReader.java:73)
	at org.hibernate.envers.configuration.metadata.reader.AnnotationsMetadataReader.getAuditData(AnnotationsMetadataReader.java:120)
	at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:77)
	at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:86)
	at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:99)
	at org.hibernate.envers.event.AuditEventListener.initialize(AuditEventListener.java:260)
	at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
	at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
	at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
	... 120 more

This happens whether I annotate any of my entities with @audited or not.  Would be grateful for any pointers/gotchas, indications that envers does play nice with Tapestry5, or even any alternative generic entity auditing facility (not trigger based) that someone could recommend - thanks.

Regards,
Jim.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org