0 Replies Latest reply on Jul 6, 2010 11:29 AM by Ron Piterman

    Envers single table Inheritance does not work? (3.5.3)

    Ron Piterman Newbie

      Hi,

       

      I am having some issue with wrong class returned from a relationship...

       

      The following test checks that envers returns the correct class from a relation of a versioned entities, where the relation points

      to an entity with  inheritance.

       

      The test fails on the last line, where envers returns the hierarchy root entity, instead of HierC3

       

      Should that work, or is it the expected result? Could my config be wrong somehow ?

       

      Thanx in advance, Ron

       

      (Test maven project is attached)

       

      Entities:

       

      HierRoot 
      HierMiddle extends HierRoot
      HierC1 extends HierRoot
      HierC2 extends HierMiddle
      HierC3 extends HierMiddle
      

       

      Test code:

       

              begin(); // start new tx
      
              AudParent parent = new AudParent();
              parent.getHiers().add( new HierC3() );
              
              entityManager.persist( parent );
              end(); // end tx and commit
              
              begin();
              Number first = getAuditReader().getRevisionNumberForDate( new Date() );
              
              AudParent p = entityManager.find( AudParent.class , parent.getId() );
              Assert.assertNotNull( p );
              Assert.assertEquals( p.getHiers().size(), 1 );
              Assert.assertTrue( p.getHiers().get( 0 ) instanceof HierC3 );
      
              p.setName( "new name" );
              entityManager.merge( p );
              
              end();
              
              
              begin();
              
              Number second = getAuditReader().getRevisionNumberForDate( new Date() );
              Assert.assertFalse( second.equals( first ) );
              
              AudParent prev = getAuditReader().find( AudParent.class, p.getId(), first );
              Assert.assertNotNull( prev );
              Assert.assertEquals( prev.getHiers().size(), 1 );
              Assert.assertTrue( prev.getHiers().get( 0 ) instanceof HierC3 , prev.getHiers().get( 0 ).getClass().getCanonicalName());
              
              
              end();