I have stumbled across some strange (to me) behavior in Seam - if I use a DAO based on java generics and inheritance I end up with a closed entity manager being injected into my DAO, if use basically the same code without generics and inheritance then everything works ok... ???
I'll explain what I'm trying to do.
I have a set of JPA entities and stateless session bean data access objects (DAOs) which I want to use from both within seam and from non-seam ejb3 applications (both within a JBoss 4.2 appserver running in Java 6).
To prevent any seam dependencies
leaking into the straight ejb3 apps, I'm defining the seam components using seam component xml files. To get seam to manage the entitymanager, I have seam configured to look-up the entity manager from the appserver JNDI.
To test my setup I have a very simple Entity, corresponding DAO and a simple
action statful session bean with a couple of xhtml facelets based pages that let me type in a text value, save a new entity with that text value then go back and create another one.
With the simple DAO I can loop round and round, creating new instances then viewing the result (and I can see the instances ending up in the database) - so it all works ok :)
With the generics and inheritance based DAO, the first loop round succeeds but the second loop fails - the exception is:
2009-06-24 15:51:25,397 DEBUG [net.sf.moksha.test.seam.test.impl.TestNewRefDataActionBean] [http-127.0.0.1-8080-1]  creating new egrefdata
2009-06-24 15:51:25,398 DEBUG [net.sf.moksha.persistence.jpa.GenericDaoJpa] [http-127.0.0.1-8080-1]  makePersistent - using entity manager: org.jboss.seam.persistence.EntityManagerProxy@458e29
2009-06-24 15:51:25,404 ERROR [javax.enterprise.resource.webcontainer.jsf.application] [http-127.0.0.1-8080-1]  javax.ejb.EJBTransactionRolledbackException: EntityManager is closed
javax.faces.el.EvaluationException: javax.ejb.EJBTransactionRolledbackException: EntityManager is closed
I have the complete log files for both scenarios and I'm quite happy to share those and the source code (if anyone would like to see it).
I'm pretty certain that its not the environment or the xml configuration thats at fault because the
simple implementation is running in the same environment and is also configured using component.xml files.
I've run out of things to look into and would appreciate any thoughts or points.