Hi There,
I am using this section of code in a web application running on Glassfish V2.
The code seems to be working fine until restart the appserver. Persistent objects are lost.
That is, not stored in the JavaDB database as expected by the find method. Can someone tell me what is wrong?
Thanks in advance,
Patrick
[i]
// Entity Manager Factory initialized at init.
EntityManagerFactory mf = javax.persistence.Persistence.createEntityManagerFactory("SomeModulePU");
....
private StoredCredential getStoredCred(String ppid) {
EntityManager em;
StoredCredential sc = null;
// Get an instance of entity manager to find
// user's stored credentials
em = emf.createEntityManager();
sc = em.find(StoredCredential.class, ppid);
em.close();
return sc;
}
private void storeCredential(String ppid, String uid,
String passwd) throws AuthLoginException {
EntityManager em = emf.createEntityManager();
em.setFlushMode(FlushModeType.COMMIT);
em.getTransaction().begin();
try {
StoredCredential sc = new StoredCredential(ppid, uid, passwd);
em.persist((Object)sc);
em.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
throw new AuthLoginException("Failed to store infocard credentials", e);
} finally {
em.close();
}
}[/i]
[Message sent by forum member 'ppetitsm' (ppetitsm)]
http://forums.java.net/jive/thread.jspa?messageID=259832