Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Lifecycle callbacks (preRemove, postRemove) not called on orphan removal
icon4.gif  Lifecycle callbacks (preRemove, postRemove) not called on orphan removal [message #1233250] Sat, 18 January 2014 22:19
Raffael Bachmann is currently offline Raffael Bachmann
Messages: 2
Registered: June 2013
Junior Member
Hi.

My problem is that the @preRemove and @postRemove functions are not called when the entity is removed because of the "orphanRemoval = true" parameter in a relation.
I think this is a bug, but in the jpa spec i haven't found a statement that actually states that the life cycle callbacks must be called after orphan removal.
So I'd like to know if i should file a bug on this?
It is quite simple to test with two classes and a simple test case. I added a maven project containing everything needed. Changing the jpa provider in the pom.xml (dependency is just commented out) shows that the behavior is different with openjpa and hibernate.
Here the most important parts to demonstrate the problem.

@Entity
public class A {
	@Id
	private int id;

	@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
	private List<B> bs = new ArrayList<B>();

	public A() {}

	public A(int id) {
		this.id = id;
	}

	public List<B> getBs() {
		return bs;
	}
}


@Entity
public class B {
	@Id
	private int id;

	@Transient
	private boolean preRemoveCalled = false;

	@PreRemove
	public void prepareRemove() {
		preRemoveCalled = true;
	}

	public B() {}

	public B(int id) {
		this.id = id;
	}

	public boolean isPreRemoveCalled() {
		return preRemoveCalled;
	}

}


@Test
public void testWithOrphanRemoal() {
	EntityTransaction et = em.getTransaction();
		et.begin();
	try {
		A a1 = new A(1);
		B b1 = new B(1);
		a1.getBs().add(b1);
		em.persist(a1);
		em.flush();
		em.refresh(a1);
		em.refresh(b1);
		a1.getBs().remove(b1);
		em.flush();
		// This fails with eclipseLink but works with openjpa and hibernate
		Assert.assertTrue(b1.isPreRemoveCalled());
	} finally {
	et.rollback();
	}
}
Previous Topic:Problem with eclipselink, pagination, join fetch, field name alias
Next Topic:Eclipselink
Goto Forum:
  


Current Time: Mon Jul 28 18:29:55 EDT 2014

Powered by FUDForum. Page generated in 0.01553 seconds