Hi All, I call
entityManager.flush()
got follow excetion. I am using Hibernate JAP
Hi All, I call
entityManager.flush()
got follow excetion. I am using Hibernate JAP
Ensure that you have an active transaction when this statement executes. If you are using JPA use EntityManager.getTransaction().begin(). This is assuming that you are using JPA outside a JTA transaction scope.
If you are running the application inside a container with JTA support you can also use JTA UserTransaction to manage transactions.
make sure your handler is 'public'
@Transactional
@RequestMapping('/test')
public String doTest() {
// do your stuff here
return 'testview';
}
Make sure that your spring configuration includes the following line:
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
mode
can be either proxy or aspectj and transaction-manager
has to point to your transaction manager been.
I am not able to update my database. my configuration file contains
I am using @Transactional annotation.
Surprisingly when I update it using JUNIT. It works fine but it is not working while updating using my application
Same was happening to me using spring 3.0.0 / 3.0.3. Data was persisted in MySQL from JUnit but not from the tomcat server. After so much work I gave up on RESOURCE_LOCAL for JTA.
This worked for me http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/ It uses JTA and depends on JOTM.
For JBoss 4.0 and Hibernate, I fixed this problem by adding some transaction manager properties to my EntityManagerFactoryBean definition:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="xaDs" />
<property name="jpaProperties">
<props>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory
</prop>
<prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup
</prop>
</props>
</property>
I found the soluton on this message board thread.
After encountering this problem myself and spending a few hours trying to get it resolved I finally found a reason for it: Spring has a bug and can't maintain transactions with @Transactional annotation if the same class has @Service annotation for the means of autowiring.
Once the @Service annotation was removed from the service class in question, and an appropriate bean was declared in the XML config:
<bean id="myService" class="com.example.myapp.service.MyServiceImpl" />
the problem is gone.
Check this JIRA bug for more details: https://jira.springframework.org/browse/SPR-5082