Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6350021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:43:53+00:00 2026-05-24T21:43:53+00:00

In case there is failure in optimistic locking I expect JPA entity manager to

  • 0

In case there is failure in optimistic locking I expect JPA entity manager to throw javax.persistence.OptimisticLockingException

Yet when I use spring orm jpa it provides ObjectOptimisticLockingException which is not related with expected one – so the question is, WTF? Do I misunderstand JPA documentation, or did the spring guys ignored standarts?

Most funny thing is that in JUnit test case proper exception is thrown ( Wrapping StaleObjectException ),
while in web app it is FUBAR. Spring configuration is reused for unit test.

Here is some code for clarity :

<!-- JPA entity manager configuration -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${database.driver}"/>
    <property name="url" value="${database.url}"/>
    <property name="username" value="${database.username}"/>
    <property name="password" value="${database.password}"/>
    <property name="testOnBorrow" value="${database.testonborrow}"/>
    <property name="validationQuery" value="${database.validationquery}"/>
</bean>

<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="defaultDataSource" ref="dataSource"/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitManager" ref="persistenceUnitManager"/>
    <property name="persistenceUnitName" value="provisioning"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="generateDdl" value="true"/>
        </bean>
    </property>
    <property name="jpaPropertyMap">
        <map>
            <entry key="hibernate.dialect" value="${hibernate.dialect}"/>
            <entry key="hibernate.hbm2ddl.auto" value="${hibernate.hbm2ddl.auto}" />
            <entry key="hibernate.hbm2ddl.delimiter.type" value="InnoDB" />
            <entry key="hibernate.show_sql" value="${hibernate.show_sql}" />
        </map>
    </property>
</bean>

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

<context:annotation-config/>

<tx:annotation-driven/>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:43:55+00:00Added an answer on May 24, 2026 at 9:43 pm

    It’s not a bug, it’s a feature. Spring’s HibernateTemplate and its interceptors around repositories translate exceptions into Spring exceptions. The idea is that if you have a Hibernate-based DAO, an iBatis-based DAO or a JDBC-based DAO, they all throw the same types of exceptions, so that the client code doesn’t have to care.

    See http://static.springsource.org/spring/docs/3.1.0.M2/spring-framework-reference/html/dao.html#dao-exceptions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following use case: There's a class called Template and with that
The case: There is a .net application calling unmanaged C code. Used method for
I think in this case there is no need to declare a public constructor
First I'll lay out what I'm trying to achieve in case there's a different
I'm considering rolling my own, but just in case there's a good piece of
we are experiencing a few problems with the IDisposable pattern. In this case there
Is there a case insensitive version of the :contains jQuery selector or should I
Is there a case when IsChecked property on WPF CheckBox null ? I guess
Is there a case-insensitive variant of the Bob Jenkins hash function? Generics.Defaults.BobJenkinsHash provides a
Is there a case of ... or context where cat file | ... behaves

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.