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

Reply via email to