7 Replies Latest reply: Jan 28, 2011 5:55 AM by Leo van den berg RSS

Envers + Hib Search + Seam

J B Novice
Hi Guys,

Would any of you guys like to make a comment on this

http://community.jboss.org/thread/161334?tstart=0



I just want to know why or whats going on under the hood.

Thanks,
JB
  • 1. Re: Envers + Hib Search + Seam
    Leo van den berg Master

    Hi,


    just read the article but I wonder what you want. I have Seam and Envers and Search working without a problem. The only problem I had was the configuration of the different Listeners. I just used the prposed seetings and it works.


    Leo

  • 2. Re: Envers + Hib Search + Seam
    J B Novice

    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.


    JB



  • 3. Re: Envers + Hib Search + Seam
    Leo van den berg Master

    Hi,


    I just checked my application:


    Hibernate 3.3.1.GA
    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.


    Leo


     

  • 4. Re: Envers + Hib Search + Seam
    J B Novice

    Hi Leo,


    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 SessionImpl under 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??


    Cheers,
    JB


  • 5. Re: Envers + Hib Search + Seam
    Leo van den berg Master

    Hi,


    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?



    Leo

  • 6. Re: Envers + Hib Search + Seam
    J B Novice

    Hi,


    I tried it with the default but no joy. Im ahead of you with the versions. Hibernate 3.6, Search 3.3 and envers 3.6, Seam 2.2.1.CR3




    Cheers,
    JB

  • 7. Re: Envers + Hib Search + Seam
    Leo van den berg Master

    Hi,


    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.


    Success,


    Leo