JPA provider vs. dialect vs. vendor in the Spring contaniner configuration

前端 未结 1 1359
我寻月下人不归
我寻月下人不归 2021-02-04 11:34

Example of spring configuration file:





        
1条回答
  •  独厮守ぢ
    2021-02-04 12:14

    Will try to explain it to you line by line:

    
    
    //Should ideally be 
    
    
    • This bean defines the jpaDialect that you are going to use. JpaDialect is an interface encapsulates certain functionality that standard JPA 1.0 does not offer, such as access to the underlying JDBC Connection. This strategy is mainly intended for standalone usage of a JPA provider; most of its functionality is not relevant when running with JTA transactions. Also allows for the provision of value-added methods for portable yet more capable EntityManager and EntityManagerFactory subinterfaces offered by Spring.
    • Since you have provided the class as class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>, this allows Spring to plug in vendor-specific behavior into Spring's EntityManagerFactory creators and it serves as single configuration point for all vendor-specific properties.It's a custom implementation of spring's own JpaVendorAdapter.

    For the second bean where you have declared:

    
        
        
    
    
    • You tell 'Spring' to configure a transactionManager whose properties are entityManagerFactory and jpaDialect. Since these properties have to specific to hibernate these are set according. The entityManagerFactory and jpaDialect are now set specifically to hibernate (or Vendor).

    As for the third bean

    
    ...
    
        
    
    ...
    org.hibernate.ejb.HibernatePersistence
    

    The tells spring to use the hibernate provider and the class org.hibernate.ejb.HibernatePersistence is Hibernate EJB3 persistence provider implementation.

    In short, you need to configure these in order to tell spring which ORM's functionality should be used.

    The reason that your application worked with configuring just persistence and provider is because the vendor adapter is automatically passed the persistence provided i.e. HibernatePersistence via the getPersistenceProvider in JpaVendorAdapter.

    Tinker around the documentation to understand how these classes are interlinked.

    EDIT : As pointed out by @TheKojuEffect , the first bean should ideally be in the form of :

    
    

    Thanks. Missed the vendorAdapter.

    You can refer :

    • HibernateJpaDialect
    • HibernateVendorAdapter
    • HibernatePersistence

    Hope it helps. :)

    0 讨论(0)
提交回复
热议问题