This content has been marked as final. Show 3 replies
You cannot use @PersistenceContext in arbitrary classes. You can only use it in classes used for servlets, enterprise beans, JSF managed beans (and probably web service end points as well). Life cycle of such objects are managed by the container - which allows container to inject the EntityManager.
Location of persistence.xml: WEB-INF/classes/META-INF/persistence.xml (In an IDE, create META-INF folder in the source directory, put the xml file there; it will automatically go to the correct location during compilation.
In the xml, if you use JTA, you should use a jta data source configured in the application server. You don't specify db connection details in this xml.
Also if you use JTA, you should be using the EntityManager inside enterprise beans. Or else to start and commit transactions, you should use an injected UserTransaction object and explicitly start and commit transactions inside methods like save().
Are you using enterprise beans or is this just a servlet application?