Why did I need to define a Hibernate-JPA vendor adapter in my Spring application context?

后端 未结 2 805
不思量自难忘°
不思量自难忘° 2021-02-05 14:53

I spent days and days trying to get a working database connection for my Spring/JPA(Hibernate) integration tests, troubleshooting mysterious \"No Database Context Found\" errors

相关标签:
2条回答
  • 2021-02-05 14:59

    First of all I am not sure why to use it but I do know that it is not mandatory to use it

    From the API Docs,

    Specify the JpaVendorAdapter implementation for the desired JPA provider, if any. This will initialize appropriate defaults for the given provider, such as persistence provider class and JpaDialect, unless locally overridden in this FactoryBean.

    The way I understand it, is an alternative to the way we specify the hibernate configurations. I did not use it, nor did I find it on Spring API docs. It is not mandatory, let it be initialized to the default value.

    There are even some issues in spring with jpaVendorAdapter told in their JIRA. Also there is an SO question here.

    0 讨论(0)
  • 2021-02-05 15:21

    I just found the answer to my question in a post on coderanch.com.

    Looks like I can circumvent the use of a JpaVendorAdapter if I just specify the JPA provider inside the persistence unit definition in persistence.xml like this:

    <persistence-unit name="myPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
                .
                .
                .
    
    0 讨论(0)
提交回复
热议问题