christian wrote:
As long as you are using release candidates and not final versions, don't do anything except upgrade.
The same happens with version:
Annotations: 3.2.0.GA
Core: version 3.2.3
EntityManager: 3.3.1.GA
Here is the Person entity
Code:
import javax.persistence.*;
@Entity
@Table(name="TPerson")
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class Person extends JPAEntity {
// Rels
// one to one rel
// side=from, from = homeaddress, to = person
@OneToOne
@JoinColumns({
@JoinColumn(name="I_ADDRESS_HOMEADDRESS", referencedColumnName="I"),
@JoinColumn(name="C_ADDRESS_HOMEADDRESS", referencedColumnName="C")})
private Address homeAddress;
public Address getHomeAddress() {
return this.homeAddress;
}
public void setHomeAddress(Address homeAddress) {
this.homeAddress = homeAddress;
}
}
Here is the Address entity
Code:
import javax.persistence.*;
@Entity
@Table(name="TAddress")
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class Address extends JPAEntity {
@OneToOne(cascade=CascadeType.PERSIST, mappedBy="homeAddress")
private Person person;
public void setPerson(Person person) {
this.person = person;
}
public Person getPerson() {
return person;
}
}
and here is the test that reproduces the fault:
Code:
public void test2() {
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("h-source");
EntityManager em = emf.createEntityManager();
Person person = new Person();
person.setPk(new EntityOid(3009, 10009));
Address address = new Address();
address.setPk(new EntityOid(3001, 10009));
// wire both sides of rel
person.setHomeAddress(address);
address.setPerson(person);
System.out.println(">> em.persist(person)");
em.persist(address);
em.getTransaction().begin();
System.out.println(">> em.getTransaction().commit()");
em.getTransaction().commit();
em.remove(person);
em.getTransaction().begin();
em.getTransaction().commit();
}
The problem happens at the final commit.
If the em.clear() is inserted before em.remove(person), the problem does not happen.
I think the problem is happening, because I am using an extended persistence context and address is still attached. When the final commit happens, firePersistOnflush() excutes in hibernate which seems to want to persist the Address. the Address cascades the Persist to the Person which is of course removed.
Do you need anything else?
Should I write a JIRA?