与春天石英不承诺 [英] Quartz with Spring not commiting

查看:140
本文介绍了与春天石英不承诺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用石英,Spring和Hibernate作为JPA提供者。数据库是Oracle。

我有一种方法将文件写入文件系统,并用细节更新数据库。
可以通过两种方式调用此方法:
$ b $ ol

  • 使用Web服务

  • 或者,作为一个预定的quatrz工作。

  • 我已经设置了石英为:

     < bean id =schedulerclass =org.springframework.scheduling.quartz.SchedulerFactoryBeanlazy-init =falsescope =singleton> 
    < property name =autoStartupvalue =true/>
    < property name =waitForJobsToCompleteOnShutdownvalue =true/>
    < property name =overwriteExistingJobsvalue =true/>
    < property name =dataSourceref =dataSource/>
    < property name =transactionManagerref =transactionManager/>
    < property name =quartzProperties>
    <道具>
    < prop key =org.quartz.scheduler.instanceName> FileScheduler< / prop>
    < prop key =org.quartz.scheduler.instanceId> AUTO< / prop>
    < prop key =org.quartz.jobStore.misfireThreshold> 6000< / prop>
    < prop key =org.quartz.jobStore.class> org.quartz.impl.jdbcjobstore.JobStoreTX< / prop>
    < prop key =org.quartz.jobStore.driverDelegateClass> $ {driverDelegateClass}< / prop>
    < prop key =org.quartz.jobStore.tablePrefix> QRTZ_< / prop>
    < prop key =org.quartz.jobStore.isClustered> true< / prop>
    < prop key =org.quartz.threadPool.class> org.quartz.simpl.SimpleThreadPool< / prop>
    < prop key =org.quartz.threadPool.threadCount> 5< / prop>
    < prop key =org.quartz.threadPool.threadPriority> 5< / prop>
    < /道具>
    < / property>
    < / bean>

    这个方法使用spring管理的事务。

    <问题是石英调度程序调用此方法时,文件被创建但数据库未更新(应更新两个表和一个表插入)。



    我也启用了hibernate show_SQL,但是在调度程序的情况下,没有update \insert语句被记录。



    虽然这个方法在调用时工作正常通过网络服务请求。日志还显示update \insert语句。



    更新1



    总结我的问题,这是我正在努力实现的:


    1. 在employee表中创建一条新记录。

    2. 将employee_id保存在job_store(石英)中。

    3. 当触发器被触发时,quartz会返回employee_id

    4. 基于此密钥检索(加载)员工记录。

    5. 向员工发送电子邮件

    6. 更新状态为已发送的通知(插入语句)

    最后,我希望所有表格都要更新。



    当石英触发工作时, strong>除了第6点。
    代码是正确的,因为当我使用Web服务调用调用此方法时,表正在更新。
    $ b 更新2



    我更新了要使用的代码

     < prop key = org.quartz.jobStore.class> org.springframework.scheduling.quartz.LocalDataSourceJobStore< /丙> 

    但是这也帮不了什么忙。



    <请帮助。谢谢。
    Adi

    解决方案

    Quartz在自己的上下文中运行,即使是由Spring便捷方法启动的,除非你明确地在 JobDataMap 中传递bean,否则最终不会获得整个Spring应用程序上下文(请参阅 http://forum.springsource.org/showthread.php?76974-Why-autowired -doesn-T工作-ON-A-QuartzJobBean豆)。所以,你可以传入Spring管理的bean,但是如果你不需要Quartz的全部功能,这一切看起来都很混乱。



    如果您的调度需求不是没那么复杂,你可能要考虑使用 @Scheduled Spring注解( see here ),因为整个方法调用本身在Spring上下文中发生,而您的交易将会像在Web服务调用中一样工作。


    I am using quartz, Spring with Hibernate as the JPA provider. Database is Oracle.

    I've got a method which writes a file to the file system and update the database with the details. This method can be called in two ways:

    1. Using a web service
    2. Or, as a scheduled quatrz job.

    I've set up quartz as:

    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false" scope="singleton">
            <property name="autoStartup" value="true"/>
            <property name="waitForJobsToCompleteOnShutdown" value="true"/>
            <property name="overwriteExistingJobs" value="true"/>
            <property name="dataSource" ref="dataSource"/>
            <property name="transactionManager" ref="transactionManager"/>
            <property name="quartzProperties">
                <props>
                    <prop key="org.quartz.scheduler.instanceName">FileScheduler</prop>
                    <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
                    <prop key="org.quartz.jobStore.misfireThreshold">6000</prop>
                    <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
                    <prop key="org.quartz.jobStore.driverDelegateClass">${driverDelegateClass}</prop>
                    <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
                    <prop key="org.quartz.jobStore.isClustered">true</prop>
                    <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
                    <prop key="org.quartz.threadPool.threadCount">5</prop>
                    <prop key="org.quartz.threadPool.threadPriority">5</prop>
                </props>
            </property>
        </bean>
    

    This method is using spring managed transaction.

    Problem is when this method is invoked by the quartz scheduler, the file gets created but the database is not updated (there should be two tables updated and one table insert).

    I've enabled hibernate show_SQL as well, but in case of scheduler no update\insert statements are getting logged.

    Though this works fine when this method is invoked by a web service request. Log shows update\insert statements as well.

    UPDATE 1

    To summarize my problem, this is what I am trying to achieve:

    1. Create a new record in the employee table.
    2. Save the employee_id in the job_store (quartz).
    3. When trigger is fired, quartz gives back the employee_id
    4. Retrieve (load) the employee record based on this key.
    5. Send Employee an email
    6. Update the Notification with status as 'Sent' (insert statement)

    In the end, I expect all the tables to be updated.

    When quartz triggers the job, all is working except point 6. Code is correct as when I invoke this method using a web service call, the table is getting updated.

    UPDATE 2

    I updated the code to use

    <prop key="org.quartz.jobStore.class">org.springframework.scheduling.quartz.LocalDataSourceJobStore</prop>
    

    but this also doest'nt help.

    Please help. Thanks. Adi

    解决方案

    Quartz runs in its own context, even if started by the Spring convenience methods, so you actually don't end up getting your whole Spring application context, unless you explicitly at a JobDataMap to pass in beans (see http://forum.springsource.org/showthread.php?76974-Why-autowired-doesn-t-work-on-a-QuartzJobBean-bean). So, you can pass in Spring-managed beans, but it all seems kind of messy if you don't need the full capabilities of Quartz.

    If your scheduling needs aren't that complex, you might want to consider using the @Scheduled Spring annotation (see here), as then the entire method call happens natively in the Spring context, and your transactions will then work as they do in the web service call.

    这篇关于与春天石英不承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆