Spring, JPA, Hibernate 3 vs 4

I'm using Spring (3.2.4.RELEASE) and Hibernate (4.2.8.Final) in my project, and using JPA configuration.

<bean id="entityManagerFactory" 
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    ...
    <property name="jpaVendorAdapter">
       <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
          ...
       </bean>
    </property>
 </bean>
 <bean id="transactionManager"
       class="org.springframework.orm.jpa.JpaTransactionManager">
     <property name="entityManagerFactory" ref="entityManagerFactory" />
 </bean>

And I use hibernate optimistic locking versioning mechanisms like below.

@Entity
public class Entity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Version
    @Generated(GenerationTime.ALWAYS)
    private int version;
}

My question is when I update Entity with wrong version, why it's throw

org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException

not

org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException ?


spring-orm-3.2.4.RELEASE contains packages for both org.springframework.orm.hibernate3.* and org.springframework.orm.hibernate4.*.

So even if you have hibernate-4.2.8.Final.jar in your project lib when you are using spring data jpa, on any kind of wrong DB operation to convert all checked exceptions to unchecked(runtime) hibernate exceptions HibernateExceptionTranslator is used from org.springframework.orm.hibernate4.HibernateExceptionTranslator.

Make sure you have used org.springframework.orm.hibernate3.HibernateExceptionTranslator in your bean configuration xml file if you want it to use 3.0.

链接地址: http://www.djcxy.com/p/89594.html

上一篇: Spring Data REST中的资源关联

下一篇: Spring,JPA,Hibernate 3和4