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:alejandroscandr...@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 <jc1000...@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:alejandroscandr...@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 <hls...@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 <jc1000...@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-unsubscr...@tapestry.apache.org
>>> For additional commands, e-mail: users-h...@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-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

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


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

Reply via email to