Announcement Announcement Module
Collapse
No announcement yet.
How do I merge JPA Items after reading? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I merge JPA Items after reading?

    I am using JpaPagingItemReader to load all the entities that have not yet been processed. I have a column called "processed_status" on each row. If the value of this column is 'U' then the query will load the entity.

    I actually use an Enum like so:

    Code:
    	<bean id="ps_unprocessed" class="org.trs.entity.enums.ProcessingStatus"
    		factory-method="valueOf">
    		<constructor-arg>
    			<value>PS_UNPROCESSED</value>
    		</constructor-arg>
    	</bean>
    
    	<bean id="itemReader"
    		class="org.trs.service.ivr.business.JpaReaderCopy">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    		<property name="pageSize" value="1000"/>
    		<property name="queryString"
    			value="from FormRequest fr where fr.requestProcessingStatus=:status" />
    		<property name="parameterValues">
    			<map>
    				<entry key="status" value-ref="ps_unprocessed" />
    			</map>
    		</property>
    	</bean>
    Once the item has been written to the output file, I'd like to set the value of this column to 'P' for processed. I set the property to the correct enum value, and then I try to merge it back into the db.

    When I try to merge the entity, though, it hangs. I can see that Hibernate issues the query, but it hangs indefinitely.

    Is there a special way I need to acquire an EntityManager? Is there a special place I need to do this "bookkeeping work" (e.g.: in a separate step).

    I'm actually injecting my DAO into a custom line aggregator and attempting to mark the item as processed from in there. I know it may not be the best design, but would this affect the proper saving (merging) of the entity?

    Has anyone done this before? If so, is there an example? I couldn't find one in the Samples project.

    Thanks,
    Dean

  • #2
    Actually updating a process indicator in a reader is not a good idea, since the items are usually buffered across a rollback. You can safely put the update in an ItemProcessor (as in the parallelJob sample), or in a ChunkListener (which could be your reader and/or line mapper).

    I'm not sure about the hanging behaviour. Probably your database has decided (incorrectly) that it needs to lock those records, or the whole table. Are you using JTA? What's the database platform, and can you try with a different one?

    Comment


    • #3
      What I ended up doing was setting the process indicator from inside my custom aggregator and wiring up a JPA Item Writer and a Flat File Item Writer in a Composite Item Writer.

      Would you still reccommend writing a custom Item Processor to set the process indicator? I'm not actually *saving* from the aggregator, just marking it processed.

      I am very interested in knowing the best practice.

      Thanks.

      Comment


      • #4
        The aggregator is a safe place to do it as well. To be on the safe side you need to make sure that after a rollback the state is rolled back locally in the VM as well as in the database. I guess in your case since you are only merging items that make it to the aggregator, it is probably fine if the local state is not strictly rolled back. You just need the merge to happen downstream of the reader.

        Comment

        Working...
        X