0

How I can configure the timeout for persiste() query of EntityManager ? I would like that the insert request never takes more time than 1 second!

Here is the code of DAO service :

@Service
@Transactional
public class DAOServiceImpl implements DAOService {

    @PersistenceContext
    private EntityManager entityManager;

    public void save(DAOBean bean) {
        entityManager.persist(bean);
    }
}

Spring config file :

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

    <property name="jndiName" value="jdbc/datasource" />
    <property name="lookupOnStartup" value="true" />
    <property name="resourceRef" value="true" />
    <property name="cache" value="false" />
</bean>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>

        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" >
                <property name="showSql" value="true"/>
            </bean>
        </property>
    </bean>

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

    <tx:annotation-driven transaction-manager="transactionManager" />
    <task:annotation-driven /> 
    <context:component-scan base-package="xx.xxx.xxx" />

</beans>

i am using sqljdbc-4.0.jar driver

Thanks.

user2602584
  • 737
  • 2
  • 7
  • 25
  • see this link http://www.objectdb.com/java/jpa/query/setting – SEY_91 Oct 12 '16 at 10:39
  • thanks for your reply ! I tried it but it doesn't work ! I set the javax.persistence.query.timeout option to 1 millisecond , unfortunately nothing was happened i didn't see any kind of Exception (QueryTimeoutException) ! – user2602584 Oct 12 '16 at 12:56

0 Answers0