Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-22235

[GSS](7.4.z) HHH-14608 Merge causes StackOverflow when JPA proxy compliance is enabled

XMLWordPrintable

      A "many to many" association (e.g. between Employee and Task in the example below) is defined using an intermediate entity (e.g. TaskParticipant in the example below) with an @Embeddable key that maps a ManyToOne association with both classes.

      @Entity
      public class Employee {
              @Id
              private String name;
      
              @OneToMany(mappedBy = "taskParticipantPK.employee", cascade = CascadeType.ALL, orphanRemoval = true)
              private List<TaskParticipant> taskParticipants;
      }
      
      @Entity
      public class Task {
              @Id
              private long id;
      
              @OneToMany(mappedBy = "taskParticipantPK.task", cascade=CascadeType.ALL)
              private List <TaskParticipant> taskParticipants;
      }
      
      @Entity
      public class TaskParticipant {
              @EmbeddedId
              private TaskParticipantPK taskParticipantPK = new TaskParticipantPK();
      }
      
      @Embeddable
      @Table(name = "TaskParticipant")
      public class TaskParticipantPK implements Serializable {
              private static final long serialVersionUID = 1;
      
              @ManyToOne(fetch = FetchType.LAZY)
              @JoinColumn(name = "employee")
              private Employee employee;
      
              @ManyToOne(fetch = FetchType.LAZY)
              @JoinColumn(name = "task")
              private Task task;
      }
      

      During merge of a detached entity on one side of the association (e.g. Employee), a non-terminating, recursive load loop is initiated resulting in an eventual java.lang.StackOverflowError. The repeating portion of the stack is shown below:

      ... java.lang.StackOverflowError
              ...
              at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1277)
              at org.hibernate.internal.SessionImpl.immediateLoad(SessionImpl.java:1119)
              at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:178)
              at org.hibernate.proxy.AbstractLazyInitializer.getIdentifier(AbstractLazyInitializer.java:89)
              at org.hibernate.type.EntityType.getHashCode(EntityType.java:372)
              at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:242)
              at org.hibernate.engine.spi.EntityKey.generateHashCode(EntityKey.java:61)
              at org.hibernate.engine.spi.EntityKey.<init>(EntityKey.java:54)
              at org.hibernate.internal.AbstractSharedSessionContract.generateEntityKey(AbstractSharedSessionContract.java:524)
              at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:879)
              at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:729)
              at org.hibernate.loader.Loader.processResultSet(Loader.java:1002)
              at org.hibernate.loader.Loader.doQuery(Loader.java:960)
              at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:351)
              at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:321)
              at org.hibernate.loader.Loader.loadEntity(Loader.java:2379)
              at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:64)
              at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:54)
              at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4289)
              at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:597)
              at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:565)
              at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:226)
              at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:122)
              at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:93)
              ...
      

              gbadner@redhat.com Gail Badner (Inactive)
              rhn-support-sfikes Stephen Fikes (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: