13 Replies Latest reply on Nov 12, 2008 4:06 AM by Amin Mohammed-Coleman

    Spring2.5 + Hibernate3.2.5 + Envers1.0

    Jure Viski Newbie

      Hy!

      I have successfully added envers to my spring hibernate configuration!
      On schema create my entity_versions table is created but
      nothing is written on version table!

      To debug I have extended VersionsEventListener overwritten onPostInsert
      and i get
      getVerCfg().isVersioned(entityName) = true

      so the listener is called and entity is versioned but nothing is writen. Why?


      regards, jure

        • 1. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
          Adam Warski Master

          Hello,

          do you have a transaction and do you commit it?
          It's really hard to say something with that little amount of data :)

          --
          Adam

          • 2. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
            Jure Viski Newbie

            Yes I have transaction manager it is HibernateTransactionManager provided by spring!

            Any additional information i will gladly give here but i don't know what!

            Database is oracle so i have created RevEntity!

            Is there something to do on overwritten method onPostInsert to get more information!

            Thank you.

            • 3. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
              Jure Viski Newbie

              Sorry, my bad!

              Everything works OK.
              I have two sessionFactories and i used transaction manager for just one session i will have to swich to JTA!

              thank you ... regards jure

              • 4. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
                Adam Warski Master

                Good that it's working :)

                --
                Adam

                • 5. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
                  Jure Viski Newbie

                  I see that many people have problems with configuration envers with spring so i will post my working config!


                  .....


                  ${hibernate.dialect}
                  ${hibernate.show_sql}
                  VER_REV_TYPE
                  VER_REV






                  <entry key="post-insert" value-ref="enversEventListener"/>
                  <entry key="post-update" value-ref="enversEventListener"/>
                  <entry key="post-delete" value-ref="enversEventListener"/>






                  That's it! Easy.

                  regards jure!

                  • 6. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
                    Jure Viski Newbie

                    One more time!!!

                    <bean id="sessionFactoryAnnot" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                     <property name="dataSource">
                     <ref bean="dataSource"/>
                     </property>
                     .....
                     <property name="hibernateProperties">
                     <props>
                     <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                     <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                    
                     <prop key="org.jboss.envers.revisionTypeFieldName">VER_REV_TYPE</prop>
                     <prop key="org.jboss.envers.revisionFieldName">VER_REV</prop>
                     </props>
                    
                     </property>
                     <property name="eventListeners">
                     <map>
                     <entry key="post-insert" value-ref="enversEventListener"/>
                     <entry key="post-update" value-ref="enversEventListener"/>
                     <entry key="post-delete" value-ref="enversEventListener"/>
                     </map>
                     </property>
                    </bean>
                    
                    <bean id="enversEventListener" class="org.jboss.envers.event.VersionsEventListener" />
                    

                    regards, jure


                    • 7. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
                      Adam Warski Master

                      Great, thanks :)
                      Just a quick note: you need 3 additional event listeners for persistent collections to work properly. See:
                      http://www.jboss.org/envers/quickstart.html

                      Adam

                      • 8. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
                        Amin Mohammed-Coleman Newbie

                        Hi

                        It looks as though I am experiencing the same problem. Whenever I create or update an entity no record is being inserted into the revisions table. all of my entities have the @versioned at the class level.

                        Here is my spring config:


                        <bean id="sessionFactory"
                         class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                         <property name="dataSource">
                         <ref local="dataSource" />
                         </property>
                         <property name="annotatedPackages">
                         <list>
                         </list>
                         </property>
                         <property name="annotatedClasses">
                         <list>
                         <value>com.amin.gigaspaces.common.domain.Address</value>
                         <value>com.amin.gigaspaces.common.domain.Contact</value>
                         <value>com.amin.gigaspaces.common.domain.Phone</value>
                         <value>com.amin.gigaspaces.common.domain.PersonalContact</value>
                         <value>com.amin.gigaspaces.common.domain.BusinessContact</value>
                         <value>com.amin.gigaspaces.common.domain.Note</value>
                         </list>
                         </property>
                         <property name="eventListeners">
                         <map>
                         <entry key="post-insert" value-ref="enversEventListener"/>
                         <entry key="post-update" value-ref="enversEventListener"/>
                         <entry key="post-delete" value-ref="enversEventListener"/>
                         </map>
                         </property>
                         <property name="hibernateProperties">
                         <props>
                         <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                         <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                         <prop key="hibernate.search.default.directory_provider">${hibernate.search.default.directory_provider}</prop>
                         <prop key="hibernate.search.default.indexBase">${hibernate.search.default.indexBase}</prop>
                         <prop key="hibernate.search.default.space_url">${hibernate.search.default.space_url}</prop>
                         <prop key="hibernate.search.default.clustered_space">${hibernate.search.default.clustered_space}</prop>
                         <prop key="org.hibernate.worker.execution">${org.hibernate.worker.execution}</prop>
                         <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
                         <prop key="hibernate.cache.use_second_level_cache">false</prop>
                         <prop key="org.jboss.envers.revisionTypeFieldName">VER_REV_TYPE</prop>
                         <prop key="org.jboss.envers.revisionFieldName">VER_REV</prop>
                         </props>
                         </property>
                         </bean>
                        
                        



                        Here is an example of my test case:


                        @Test
                         @Transactional
                         @Rollback(false)
                         public void testEntityVersionManager() throws Exception {
                         PersonalContact pc = (PersonalContact) hibernateTemplate.get(PersonalContact.class, new Long(1));
                        
                         pc.setEmail("ljktrt@new.com");
                        
                         hibernateTemplate.update(pc);
                         hibernateTemplate.flush();
                        
                         }
                        
                        



                        I am using version 1.0.0.

                        Any help would be appreciated!

                        • 9. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
                          Adam Warski Master

                          Are you sure the event listeners get registered? Why don't you specify them in hibernate properties?

                          (but again: I'm no expert on Spring, quite the contrary)

                          --
                          Adam

                          • 10. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
                            Amin Mohammed-Coleman Newbie

                            Hi

                            I can see the listeners being fired when debugging but no entries into the tables. The only thing that is being stored is the revision id and revision timestamp in the _revisions_info table.


                            Will try to debug further...
                            Cheers
                            Amin

                            • 11. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
                              Adam Warski Master

                              That's weird ... are you sure you have a transaction which you commit?

                              Adam

                              • 12. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
                                Amin Mohammed-Coleman Newbie

                                Yep. My data is being inserted into the database table. To be honest I don't understand why this isn't working as I had been doing prototype work with this framework and it worked. Very strange..will keep on looking.

                                • 13. Re: Spring2.5 + Hibernate3.2.5 + Envers1.0
                                  Amin Mohammed-Coleman Newbie

                                  This is working now. I had a test execution listener which was causing the problem and not writing to the db.

                                  Thanks.