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.1 person found this helpful
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?
Thanks for helping. Do you have an example persistence.xml I may see? I am using mysql and glassfish. I have configure a DataSource in glassfish called MySQL.
961389 wrote:Google can point you to a great number of them.
Thanks for helping. Do you have an example persistence.xml I may see?