Example of spring configuration file:
Will try to explain it to you line by line:
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
//Should ideally be
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
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:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"ref="entityManagerFactory"/>
<property name="jpaDialect"ref="jpaDialect"/>
</bean>
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
<property name="jpaDialect"ref="jpaDialect"/>
...
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
...
<provider>org.hibernate.ejb.HibernatePersistence</provider>
The <provider>
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 :
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
Thanks. Missed the vendorAdapter
.
You can refer :
Hope it helps. :)