views:

45

answers:

1

Hi,

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.

+4  A: 

Every JPA example and tutorial have main method to run it.

That's only useful for code that is intended to run outside a container, which is often the case of tutorials.

I don't have main method in my web application's server side code. Is that a problem in point of using JPA.

No. Absolutely not.

Or Creation of EntityManager & EntityManagerFactory in other classes is allowed.

There is no particular restriction on EntityManagerFactory and EntityManager (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 an EntityManager at the start of a request and to flush and close it at the end).

And it would be appreciative, if anyone explain me about using Hibernate in JPA.

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.

Pascal Thivent