1 Reply Latest reply on Apr 7, 2009 4:12 AM by brochaxc

    Problem saving object with empty collection

      Hello,
      I have an object that inherits from a base class that contains a number of collections - 3 sets and 1 list. The collections are initialized to empty collection objects on construction as follows:

      @Entity
      @Audited
      public abstract class Person{
      
       @ManyToMany
       @JoinTable(
       name = "PeoplesClothes",
       joinColumns = {@JoinColumn(name = "personID")},
       inverseJoinColumns = {@JoinColumn(name = "clothesID")})
       private Set<Clothes> clothes= new HashSet<Clothes>();
      
       @ManyToMany
       @JoinTable(
       name = "PeoplesThings",
       joinColumns = {@JoinColumn(name = "personID")},
       inverseJoinColumns = {@JoinColumn(name = "thingID")})
       private Set<Thing> costSheet = new HashSet<Thing>();
      
       @ManyToMany
       @JoinTable(
       name = "PeoplesCars",
       joinColumns = {@JoinColumn(name = "personID")},
       inverseJoinColumns = {@JoinColumn(name = "carID")})
       private Set<Car> route = new HashSet<Car>();
      
       @OneToMany
       @OrderBy("priority")
       @JoinTable(
       name = "PeoplesFriends",
       joinColumns = {@JoinColumn(name = "personID")},
       inverseJoinColumns = {@JoinColumn(name = "friendID)}
       )
       @org.hibernate.annotations.IndexColumn(name = "friend_PRIORITY")
       private List<Friend> friends= new ArrayList<Friend>();



      When I try to construct the object and leave the collections empty I get the following error (I think when its processing the list collection - but i am not 100% sure):

      java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      at java.lang.String.substring(String.java:1938)
      at java.lang.String.substring(String.java:1905)
      at org.hibernate.envers.synchronization.work.PersistentCollectionChangeWorkUnit.(PersistentCollectionChangeWorkUnit.java:49)
      at org.hibernate.envers.event.AuditEventListener.onCollectionAction(AuditEventListener.java:208)
      at org.hibernate.envers.event.AuditEventListener.onPostRecreateCollection(AuditEventListener.java:243)
      at org.hibernate.action.CollectionRecreateAction.postRecreate(CollectionRecreateAction.java:93)
      at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:66)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
      at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
      at com.xconnect.peering.test.TestRegistry.buildPeeringValues(TestRegistry.java:1049)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
      at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
      at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
      at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
      at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
      at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
      at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
      at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
      at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
      at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


      What is causing this? I have similar code in other classes and it works fine - I don't see what the difference is between the cases where it works and where it doesn't.

      Thanks,
      Brocha