Hi,
I'm struggling with a @PostPersist lifecycle callback where I want to execute persist() on the entity manager bound to enterprise bean's environment. It appears that entitymanagers are not in JNDI in GlassFish v2 b58g and hence the exception upon executing persist() in @PostPersist method. Why is so? It works fine in Geronimo 2.1.
The bean:
@PersistenceContext(name="persistence/InventoryAppMgr", unitName="ear-ejb-beanname-ejbPU")
@Stateless(name="PolskoAngielskiSlownik")
public class PolskoAngielskiSlownik implements Slownik {
@PersistenceContext(name="entitymanager")
EntityManager em;
@Resource SessionContext ctx;
public String przetlumacz(String slowo) {
((EntityManager)ctx.lookup("persistence/InventoryAppMgr")).persist(new Slowo(slowo));
return "pl->ang: " + slowo;
}
the entity Slowo:
@Entity
public class Slowo implements Serializable {
...
@PostPersist
protected void postPersist() {
try {
((EntityManager)new InitialContext().lookup("java:comp/env/persistence/InventoryAppMgr")).persist(new WpisDoKapownika(slowo));
} catch (Exception e) {
e.printStackTrace();
}
}
}
Another entity - WpisDoKapownika:
@Entity
public class WpisDoKapownika implements Serializable {
...
@PostPersist
protected void postPersist() {
System.out.println("Wpis do kapownika o tresci: " + wpis + " zapisany");
}
}
Jacek
http://www.jaceklaskowski.pl
[Message sent by forum member 'jlaskowski' (jlaskowski)]
http://forums.java.net/jive/thread.jspa?messageID=254904