Another @OneToMany+@JoinColumn Question
billgloff6 Jan 6, 2011 5:09 PMHi 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
@Entity
@Table(name="Users")
@Indexed
@Audited
@org.hibernate.annotations.Entity(dynamicUpdate = true)
public class User extends DateBaseEntity{
@OneToMany(cascade=CascadeType.ALL)
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@JoinColumn(name="USERID", nullable=false)
@AuditMappedBy(mappedBy = "user")
@AuditJoinTable(name = "Shelf_AUD")
private List<UserBook> shelf = new ArrayList<UserBook>();
...
}
and my Many mapped as
@Entity
@Indexed
@Table(name="Shelf")
@Audited
@AuditTable(value="Shelf_AUD")
@org.hibernate.annotations.Entity(dynamicUpdate = true)
public class UserBook extends BaseEntity {
@ManyToOne (fetch = FetchType.EAGER)
@JoinColumn(name="KTSID")
private Book book;
@ManyToOne
@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.
Thanks,
Bill