在entityManager上设置超时查询

时间:2016-10-12 09:06:18

标签: java spring hibernate entitymanager hibernate-entitymanager

如何为EntityManager的 persiste()查询配置超时?我希望插入请求永远不会花费超过1秒的时间!

以下是DAO服务的代码:

@Service
@Transactional
public class DAOServiceImpl implements DAOService {

    @PersistenceContext
    private EntityManager entityManager;

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

Spring配置文件:

<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>

我正在使用sqljdbc-4.0.jar驱动程序

感谢。

0 个答案:

没有答案