Hello,
I have an EJB that needs some cleaning up before it can be deleted. So I tried adding a method annotated with "@PreDestroy" but supprisingly this method is never called.
So my first question is, is this a known problem? My second question is, is there a workaround?
Just as an example, I created an ejb named testEJB with the following methods:
[i]
@PrePersist
public void prepersist(){
System.out.println("prepersist");
}
@PostLoad
public void postload(){
System.out.println("postload");
}
@PreDestroy
public void predestroy(){
System.out.println("predestroy");
}
[/i]
I then created a servlet with 2 buttons, one "add ejb" button (which creates a new ejb) and one "remove All" (which removes all these test-ejbs. Each time this page is called, it also counted how many ejb's there were. you can find these source-files appended to this message.
After pressing "add ejb" once there appeared on my console:
[i]prepersist
postload[/i]
I pressed it again and it said:
[i]prepersist
postload
postload[/i]
Finally I pressed "remove All" and my console said:
[i]postload
postload[/i]
However, this should have been
[i]postload
postload
predestroy
predestroy[/i].
This indicates that the @PreDestroy annotation is simply ignored.
As for my system, I'm using GlassFish V2 with NetBeans 6.0.1 on a mac running OSX Leopard.
greetz,
sjoekie
(as I can only attach 2 files, you'll have to create the facades yourself.)
postload[/i]
However, there was no "predestroy" message on my console, and still they were destroyed.
Greetz,
Sjoekie
[Message sent by forum member 'sjoekie' (sjoekie)]
http://forums.java.net/jive/thread.jspa?messageID=264086