Always set the value of jta-data-source and non-jta-data-source in your persistence.xml file. Regardless if targeting your EntityManager usage for transaction-type="RESOURCE_LOCAL" or transaction-type="TRANSACTION", it's very difficult to guarantee one or the other will be the only one needed. Often times the JPA Provider itself will require both internally to do various optimizations or other special features.
See Containers and Resources
for how to configure 'JtaManaged' and a full list of
A warning for any new JPA user is by default all objects will detach at the end of a transaction. People typically discover this when the go to remove or update an object they fetched previously and get an exception like "You cannot perform operation delete on detached object".
All ejb methods start a transaction unless a) you configure them otherwise , or b) the caller already has a transaction in progress when it calls the bean. If you're in a test case or a servlet, it's most likely B that is biting you. You're asking an ejb for some persistent objects, it uses the EntityManager in the scope of the transaction started around it's method and returns some persistent objects, by the time you get them the transaction has completed and now the objects are detached.
All edits are reviewed before going live, so feel free to do much more than fix typos or links. If you see a page that could benefit from an entire rewrite, we'd be thrilled to review it. Don't be surprised if we like it so much we ask you for help with other pages :)NOTICE: unless indicated otherwise on the pages in question, all editable content available from apache.org is presumed to be licensed under the Apache License (AL) version 2.0 and hence all submissions to apache.org treated as formal Contributions under the license terms.