2 Replies Latest reply on Aug 16, 2010 8:40 AM by Robin G

    @OneToMany NPE at ListCollectionInitializor.addToCollection : 73

    Ron Piterman Newbie

      Hi,

       

      I am evaluating Envers and have a test settings:

       

      @Entity
      @Audited
      public class AudChild {
          @Id @GeneratedValue
          private Long id;
          @ManyToOne(optional=false,cascade=CascadeType.ALL)
          @JoinColumn
          private AudParent parent;
          private String name;
      ...
      }
      
      @Entity
      @Audited
      public class AudParent {
          @Id @GeneratedValue
          private Long id;
          private String name;
          @Audited(modStore=ModificationStore.FULL,targetAuditMode=RelationTargetAuditMode.AUDITED)
          @OneToMany(mappedBy="parent",cascade=CascadeType.ALL)
          @OrderColumn(name="index")
          private List<AudChild> children = new ArrayList<AudChild>();
      
      ...
      }
      

       

      In my test I have the following code:

       

      AudParent p = new AudParent("p1");
      AudChild c = new AudChild(p, "c1");
      
      entityManager.persist( c );
      p.getChildren().add( c );
      entityManager.persist( p );
      
      end(); // end tx
      
      begin(); // begin new tx
      
      AudParent same = entityManager.find( AudParent.class, p.getId() );
      
      Assert.assertNotNull( same );
      Assert.assertTrue( same.getChildren().size() == 1 );
      
      Number rev = getAuditReader().getRevisionNumberForDate( new Date() );
      Assert.assertNotNull( rev );
      
      AudParent versioned = getAuditReader().find( AudParent.class, p.getId(), rev );
      Assert.assertNotNull( versioned );
      Assert.assertEquals( versioned.getName(), "p1" );
      Assert.assertTrue( versioned.getChildren().size() == 1 ); // Exception here
      
      end();
      
      

       

      And on the last assert I get an exception:

       

      java.lang.NullPointerException
          at org.hibernate.envers.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:73)
          at org.hibernate.envers.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:39)
          at org.hibernate.envers.entities.mapper.relation.lazy.initializor.AbstractCollectionInitializor.initialize(AbstractCollectionInitializor.java:67)
          at org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy.checkInit(CollectionProxy.java:50)
          at org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy.size(CollectionProxy.java:55)
          at hibtest.envers.EnversTest.persistAndChange(EnversTest.java:43)
      
      

       

      Can anyone point me to what am I doing wrong here?

       

      Attached is a maven project which includes the test. Extract and enter "mvn install"...

       

      Thanx in advance, Ron