5 Replies Latest reply on Oct 1, 2008 6:29 AM by Adam Warski

    Entity caching?

    Andrew DePue Newbie

      I've run into a problem, and I'm not sure if it is me or an Envers bug. I have an Entity (let's just say the class is named Enitity) that contains a list of records (we'll call them EntityRecords). A bidirectional relationship exists between these two. The entity maps to the records like so:

      @OneToMany(targetEntity = EntityRecord.class, cascade = CascadeType.ALL, mappedBy = "entity", fetch = FetchType.LAZY)
       public List<EntityRecord> getRecords()


      The records map to the entity like so:
      @ManyToOne(targetEntity = Entity.class, fetch = FetchType.LAZY)
       public Entity getEntity()

      When I try to restore one of these via the Envers VersionsReader, every EntityRecord gets a different lazy-init Entity proxy, and all those are different than the main Entity. Under normal Hibernate usage, each EntityRecord just gets the already initialized main Entity instance. This creates infinite recursion in one case where the act of accessing one of the Entity proxies from an EntityRecord in turn causes a new Entity to be loaded (new Java instance, but same business instance) with a new set of EntityRecords, which all reference new Entity proxies, each of which will try to load a new set of EntityRecords, and so on.
      Is this a configuration issue, a known issue with Envers, or a bug?

      Thanks!