For the last three days i am learning JPA by various examples, to change my JDBC code to JPA. Every JPA example and tutorial have main method to run it. Of course,
in main method only they defining EntityManager & EntityManagerFactory.
I dont have main method in my web application’s server side code. Is that a problem in point of using JPA. Or Creation of EntityManager & EntityManagerFactory in other classes
is allowed.
and it would be appreciative, if anyone explain me about using hibernate in JPA.
That’s only useful for code that is intended to run outside a container, which is often the case of tutorials.
No. Absolutely not.
There is no particular restriction on
EntityManagerFactoryandEntityManager(beyond the fact that the EMF should be created once for the lifetime of the application and that the common pattern for the EM in a web application is entityManager-per-request i.e. to open anEntityManagerat the start of a request and to flush and close it at the end).Hibernate can be used as JPA provider (more precisely, the implementation is provided by the satellite project Hibernate EntityManager). But your question is too vague. If you have a specific problem, open another question and describe it.