No transaction when using Spring websocket

I have installed websocket with @MessageMapping annotation as usual. It works fine, but when I call some method surrounded by @Transactional and I try to do some update on the database, I get the error:

javax.persistence.TransactionRequiredException: Executing an update/delete query.

      

It seems that the transaction manager is not working in this case. However, when this same method is called from the Rest controller, everything goes well. Does anyone know what's going on?

thank

+3


source to share


1 answer


I replaced the XML config:

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

      

with JAVA config:



@Configuration
@EnableTransactionManagement
public class AppConfig {
   @Autowired
   private EntityManagerFactory entityManagerFactory;

   @Bean
   public PlatformTransactionManager transactionManager() {
       return new JpaTransactionManager(entityManagerFactory);
   }
}

      

and it works.

0


source







All Articles