OneToMany + JoinTable versioning
fgc_fernando Oct 14, 2008 1:02 PMHello Folks,
I'm having a problem with versioning of a OneToMany relationship + JoinTable with envers.
Consider these classes:
(A Person can have many pets, but a pet belongs to just one Person.)
Person:
// imports omitted for brevity... @Versioned @Entity public class Person { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE) @Column(name="person_id") private long id; @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY) @JoinTable(name="person_pet", joinColumns=@JoinColumn(name="person_id",referencedColumnName="person_id"), inverseJoinColumns=@JoinColumn(name="pet_id",referencedColumnName="pet_id")) private Set<Pet> pets; public Person(){ this.pets = new HashSet<Pet>(); } // gets and sets omitted for brevity... }
Pet:
// imports omitted for brevity... @Versioned @Entity public class Pet { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE) @Column(name="pet_id") private long id; private String name; public Pet(){} // gets and sets omitted for brevity... }
When I generate the database, envers creates a table called "person_pet_versions" which is supposed to contain the changes in the relationship between persons and pets.
The problem is that when I associate persons with pets, nothing is inserted into "person_pet_versions" table.
The test code:
// imports omitted for brevity... public class Test { public static void main(String[] args) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("testenvers"); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); Person me = new Person(); me.getPets().add(new Pet("Fido")); me.getPets().add(new Pet("Max")); em.persist(me); tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } } }
After executing the Test class, all the data is in the database, but the person_pet_versions table is empty.
I'm using:
Envers 1.1.0 beta2 for hibernate 3.3
Hibernate 3.3.1.GA
I already tested:
Envers 1.1.0 beta 2
Envers 1.1.0 beta 1
with
Hibernate 3.2.6
The docs say that a OneToMany + JoinTable versioning should work in envers 1.1.0 beta.
Am I doing something wrong?
Thanks in advance
by the way, this is an excelent framework. Its saving me a lot of time ;)