Do I need hibernate.cfg.xml if I use JPA?


I just learnt that it is better to use EntityManager for transaction management in a JEE web app.

However, many tutorials suggested that I have to create a persistence.xml file.

I’d like to know should I keep the hibernate.cfg.xml file now that I am going to create persistence.xml file and using Entity Manager (which I read is easier compared to hibernate SessionFactory)

You don’t need it. You need just the persistence.xml configuration file if you use JPA.

Alright thanks.

I’m rather confused regarding EntityManager cos EJB also has a EntityManager and EJB/JEE has a dependency injection etc etc…

So, now my question, where does Hibernate comes in given the above ?

EJB is a spec, just like JPA. Hibernate implements the JPA spec. The User Guide explains all this in more details.