• Post Reply Bookmark Topic Watch Topic
  • New Topic

Spring - JPA/Hibernate @Schedular and @Transactional  RSS feed

 
Atul More
Ranch Hand
Posts: 67
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using Spring and JPA/Hibernate for my project.
I am writing a job using spring @Schedular mechanism.
I am facing very strange issue here, not able to update the DB values within transaction. I am using @Transactional annotation.

Is there anything which I am missing? The job is getting called, able to read the data but not able to update the DB values.

Any idea?


Thanks,
Atul
 
Mayank Kumar Sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

You will need to add below writed code into context.xml

<tx:annotation-driven transaction-manager="transactionManager" />


and  configure entity manager with below bean

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


afterwards, you are suppose to use below cited lines for service creation in class boundry

@Service
@EnableTransactionManagement
public class Service {

//method
@Transactional(propagation = Propagation.REQUIRED)
public void save(Entity entity) {

        .
        .
        .
        }



}

 
Atul More
Ranch Hand
Posts: 67
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Its too late to answer this post. 
I solved the issue, I used @Configuration annotation in schedular class instead of it I have to use @Service annotation.
The problem was solved..

Thanks,
Atul
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!