5 Replies Latest reply on Jan 29, 2011 3:48 PM by Adam Warski

    Another @OneToMany+@JoinColumn Question

    Bill Gloff Newbie

      Hi everyone!


      First of all, I've read and searched for all similiar situations as I know this is a hot topic, but I couldn't find anything exactly what I'm experiencing.


      I'm using jboss.envers-1.2.3-hibernate-3.3 in JBoss 5 and I'm having an issue where after I query for a user using



            AuditQuery query = getAuditReader().createQuery().forRevisionsOfEntity(User.class, false, true).add(AuditEntity.id().eq(id));


      I always get an empty List returned for user.getShelf() (for all revisions) even though revisions get created when I add a book to the user's shelf. I also noticed that in the DB table, the AUD table has all the columns filled except for the userId FK. Not sure why that is getting lost. Of course if I remove the @AuditMappedBy annotation, I get an error


            Violation of PRIMARY KEY constraint 'PK__Shelf_AU__1EB'. Cannot insert duplicate key in object 'cafescribeadmin.Shelf_AUD'.



      So I have my One entity mapped as


      @org.hibernate.annotations.Entity(dynamicUpdate = true)
      public class User extends DateBaseEntity{




          @JoinColumn(name="USERID", nullable=false)
          @AuditMappedBy(mappedBy = "user")
          @AuditJoinTable(name = "Shelf_AUD")
          private List<UserBook> shelf = new ArrayList<UserBook>();







      and my Many mapped as


      @org.hibernate.annotations.Entity(dynamicUpdate = true)
      public class UserBook extends BaseEntity {


          @ManyToOne (fetch = FetchType.EAGER)      
          private Book book;
          @JoinColumn(name="USERID", insertable=false, updatable=false)
          private User user;





      Does anyone see what I am doing wrong? It's strange to me that it does in fact create a separte revision when this object gets added/deleted to the collection but doesn't keep the FK relation when querying the revisions.


      Let me know if I can provide any more information.