Is persistence.xml requied when working with Spring and Hibernate?

前端 未结 3 2032
清酒与你
清酒与你 2020-12-04 18:21

I am using a project with Spring JPA and Hibernate. Most of the things in persistence.xml can be specified in Spring applicationContext.xml file.

S

3条回答
  •  Happy的楠姐
    2020-12-04 18:56

    The JPA specification does not state anywhere that the file is required, but in the definitions of the contracts of EntityManagerFactory and EntityManager and practically throughout the whole specification, the persistence.xml file is mentioned over and over.

    I recently had to deal with the question of whether it is possible to programatically configure JPA 2.0 with Hibernate 3.6 without using persistence.xml at all.

    I concluded that this is not possible, although you can configure the file to contain a very minimum configuration. I determined that the file must at least contain the name of your persistence unit. The rest of the info can be programatically provided to the entity manager factory as parameters.

    I have never used spring though, therefore I do not know if it uses any tricks to overcome this issue.

提交回复
热议问题