Skip to main content


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] Sun, 19 January 2014 03:19 Go to next message
Raffael Bachmann is currently offline Raffael BachmannFriend
Messages: 4
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();
	}
}
Re: Lifecycle callbacks (preRemove, postRemove) not called on orphan removal [message #1577534 is a reply to message #1233250] Wed, 21 January 2015 23:46 Go to previous messageGo to next message
Pedro Silva is currently offline Pedro SilvaFriend
Messages: 2
Registered: January 2015
Junior Member
Hi Raffael,

I'm facing the same problem. Have you reported the bug? Or have you found a work around in meantime?

If not I'm going to file it.
Re: Lifecycle callbacks (preRemove, postRemove) not called on orphan removal [message #1578532 is a reply to message #1577534] Thu, 22 January 2015 13:04 Go to previous message
Raffael Bachmann is currently offline Raffael BachmannFriend
Messages: 4
Registered: June 2013
Junior Member
Hi Pedro,

honestly I do not remember what i did. I think i might have worked around and forgot the problem.
I quickly searched bugzilla and I couldn't find a bug report from me.
Sorry.
Previous Topic:NullPointerException when using flush()
Next Topic:Unable To Generate MetaModel For Entity
Goto Forum:
  


Current Time: Fri Apr 19 21:28:43 GMT 2024

Powered by FUDForum. Page generated in 0.02838 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top