Question is though how did you use your entity manager?? If i inject the factory and create the entity manager programtically it works fine however if i let seam inject the entity manager it uses a proxy underneath and this is where i had my problems.
The injected entity uses a proxy and this does not use the same connection as that envers was using so when a commit occurs nothing gets flushed to the audit tables.
I just checked my application:
Hibernate Search 3.0.1.GA
Envers 1.2.1 GA
I also use the Hibernate spatial extensions.
The configuration for search and Envers in persistence.xml:
<property name="hibernate.search.default.directory.provider" value="org.hibernate.search.store.FSDirectoryProvider" /> <property name="hibernate.search.default.indexBase" value="../server/default/lucene/indexes" /> <property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.post-update" value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.post-delete" value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener" /> <property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener" /> <property name="org.hibernate.envers.auditTablePrefix" value="AUD_" /> <property name="org.hibernate.envers.auditTableSuffix" value="" /> <property name="org.hibernate.envers.revisionFieldName" value="ver_rev" />
And as stated, works great.
Just a recap of the original link.
I had a standalone test case that worked fine no problems. I had a work flow which was the exact same as the standalone test case but in my webapp which uses seam.
Now after spending a few days fooling around with it i figured what the problem was
In my component i would let seam inject the entity manager, like so
@In private EntityManager updateEntityManager;
Now seam doesnt use
SessionImplunder the hood for the entityManager implementation, it uses one of its own proxy objects. And this what was causing my problem. A transaction would start, unit of work carried out and then committed. I could see the insert SQL in the log file but no insert into the database. The reason why is explained in detail in the original link
To fix my problem in seam i had to stop injecting the entityManager into my component like above but start using the factory and from there create an entity manager. The entity manager impl no longer would use the proxy impl but the org.hibernate.SessionImpl
@In EntityManagerFactory entityManagerFactory;
So a question to you was how do you get a hold of the entityManager in your application?? Do you inject it in directly or do you use the factory to create it??
I just use the default Seam injection for the entityManager, with the default name (entityManager) and I don't have to do anything additional.
When I update an Audited entity with included text search, Hibernate-Envers and Hibernate-Search are perfectly intercepted by Hibernate, things are stored where they should be stored.
Have you tried using the default EntityManager naming?
If it's easy just go back a
Seam-version. The really big change is in the AS6 support (including all related standard stuff, EJB, JSF etc.) If you're using JBOSS AS5 or something else I would stick to Seam 2.1.2 GA or 2.2.0 GA. We've have our application working under both environments and it works. The 2.2 is finally for production because of its multi-War improvements.