Hi I am using hibernate JPA with spring and mongodb and i am running my application on Glassfish-4.0.
My service class is :
@Component
public class T
I have also faced same issue when I work with Hibernate and Spring Jpa Data Repository. I forgot to place @Transactional
on spring data repository method.
Its working for me after annotating with @Transactional
.
as form the configuration xml it is clear that you are going to use spring based transaction. Please make sure that the import which you are using for @Transactional is "org.springframework.transaction.annotation.Transactional"
in your case it might be "javax.transaction.Transactional"
cheers
Chetan Verma
After integrating Spring 4 with Hibernate 5 in my project and experiencing this problem, I found that I could prevent the error from appearing by changing the way of getting the session from sessionFactory.openSession()
to sessionFactory.getCurrentSession()
.
the proper way to work out this bug may be keep using the same session for the binding transaction.opensession will always create a new session which doesnt like the former one holding a transaction configed.using getCurrentSession and adding additional property <property name="current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</property>
works fine for me.
Faced the same problem, I simply forgot to activate the transaction management with the @EnableTransactionManagement
annotation.
Ref:
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/EnableTransactionManagement.html
I was facing the same error inspite of adding @Transactional
annotation at class level and importing org.springframework.transaction.annotation.Transactional
.
Then I realized that since I was using hibernate query, I had imported javax.persistence.Query
instead of import org.hibernate.query.Query
.
Therefore adding import org.hibernate.query.Query
solved the issue for me.
I hope this idea helps someone.
In my case, I had the wrong @Transactional
imported.
The correct one is:
import org.springframework.transaction.annotation.Transactional;
and not
import javax.transaction.Transactional;