• Register
0 votes
3.7k views

Problem :

I am getting bellow error while  using hibernate JPA with spring and mongodb and running my application on Glassfish-4.0.

javax.persistence.transactionrequiredexception: executing an update/delete query

6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution:

I was simply creating the native query from the persistence EntityManager to perform the update.

Query query = entityManager.createNativeQuery(queryString);

I was receiving the following error:

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

Many solutions suggest adding @Transactional to your method. By just doing it did not change my error.

I then tried use of application managed entity managers and not container managed and that was joinTransaction().

Kept @Transactional for decorating the method and then called joinTransaction() on EntityManager object just prior to calling query.executeUpdate() and my native query update worked.

Further Readings:

https://github.com/spring-projects/spring-boot/issues/3576

9 7 4
38,600 points

Related questions

0 votes
1 answer 49 views
49 views
Problem: Why I got the error :javax.persistence.transactionrequiredexception: executing an update/delete query.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
2 answers 769 views
769 views
Problem : I am new to the Spring and JPA, wasted 10 days and no result with the searching on internet. I want to save the object to SQL SERVER, my connection is correct but when I write .flush() I get below exception “nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress”
asked Jan 21, 2020 jwilliam 3.9k points
0 votes
1 answer 436 views
436 views
Problem : I am new to Spring and JPA I want to save object to SQL SERVER, connection is correct but when I write .flush() I get the exception as below javax.persistence.TransactionRequiredException: no transaction is in progress
asked Oct 22, 2019 peterlaw 6.9k points
0 votes
1 answer 49 views
49 views
Problem: HELP! I need help understanding this error: Error creating bean with name 'entitymanagerfactory' defined in class path resource.
asked Mar 6 Wafa Abu Yousef 6.1k points
1 vote
1 answer 5.3K views
5.3K views
Problem : When I try to compile my spring project, I always face the below error : Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed I have the ... >1.4.1.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> . . .
asked Dec 12, 2019 alecxe 7.5k points
0 votes
1 answer 32 views
32 views
Problem : I am a completely novice in the hibernate world and facing this error: Generationtarget encountered exception accepting command : error executing ddl via jdbc statement .
asked Mar 13 Wafa Abu Yousef 6.1k points
0 votes
1 answer 2.5K views
2.5K views
Problem : I am a completely novice in the hibernate world and facing below error, WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement The ... hibernate 4 version all my code runs very well. I looked for many solutions but they are not working for me.
asked Feb 4, 2020 jwilliam 3.9k points
0 votes
1 answer 9 views
9 views
Problem: I am developing a JavaSE application using JPA. Unfortunately, I get null after calling: Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
asked Apr 24 ummeshani 10.8k points
0 votes
1 answer 84 views
84 views
Problem : After executing spring boot with h2 database and JPA i am facing below error, any help: org.hibernate.tool.schema.spi.commandacceptanceexception: error executing ddl via jdbc statement
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 5.2K views
5.2K views
Problem : After executing spring boot with h2 database and JPA i am facing below error org.hibernate.tool.schema.spi.commandacceptanceexception: error executing ddl via jdbc statement
asked Nov 12, 2019 peterlaw 6.9k points