After upgrading to spring boot 1.2.5 an exception is being thrown when attempting to execute the below query.
Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
#Modifying
#Transactional
#Query(value = "insert into some_table (some_id) VALUES (?1)", nativeQuery = true)
public void insertSomeTable(long some_id);
It's as if the #Transactional annotation is being ignored. With spring boot 1.2.1 this works. Any ideas?
tl;dr
You're apparently using JTA 1.2's #javax.transaction.Transactional and the support for that is unfortunately broken in the Spring Data release that Boot release includes. The workaround is to use Spring Framework's #org.springframework.transaction.Transactional.
Details
The Spring Data release included with that Spring Boot version ships a fix for a transaction bug that existed before. This effectively "fixes" the transaction handling on repositories to be controlled by Spring Data.
Unfortunately that switches of the support for JTA 1.2's #Transactional which you are apparently using. I've fixed DATACMNS-732 (to bei included in Fowler SR2 and Gosling RC1) and created a ticket in Spring Framework to improve the scenario within the library (we basically suffered from not picking up JTA 1.2 support due to the need to copy a class).
Related
I'm facing some problems about spring boot version.
When I used the older version of spring boot, 2.1.6.RELEASE, the following query passed query validator and works well as intended.
#Query("select new a.b.c.CustomDto(entity) from Entity entity where ...")
Page<CustomDto> getCustomDtoList(#Param("parameter1") ..., Pageable pageable);
But after I bumped up the spring boot version to 2.3.0, it occurs QuerySyntaxException which means it seems not to allow such a syntax of writing query.
More specifically, the error occurs when the hibernate generates count query for the given query. seriously, it says "unexpected token: count".
Can't I use this syntax anymore on 2.3.0 of spring jpa? TIA.
I am using hibernate for the REST API. Right now all the transactions are handled by explicitly calling beginTransaction and transaction.commit. The transaction is rolled back in case of a failure. I am looking to use #Transactional instead of all the beginTransactions and commit transactions. Could someone tell me how can I integrate #Transactional in my hibernate. I am using mysql for querying the database.
You can annotate your query method with #Transactional so you get your transaction opened, commited and closed when your method ends.
Be careful about isolation levels (https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Transactional.html#isolation--) because it indicates when Spring will create a new session for your transaction, or simply use already opened one.
When you thrown an exception on your method, transaction gets an automatic rollback and you're good :)
You can use Spring Framework with Hibernate Integration. The advantage is spring manages the Hibernate session's and all the low level things that we have to manage manually in hibernate like granular commit etc. Here is the example of this. this is older repository so uses older version of Spring and Hibernate but you can upgrade it here
On my current project we are using Spring 4.2 (core, aop, beans, web , webmvc, etc).
What are the major problems we could encounter when upgrading from Spring 4.2 to Spring 5.0.5? How backward compatible would Spring Security 4.2 be with Spring 5.0.5?
Thank you for your time.
It's hard to tell without knowing which functionalities and features of Spring your project relies on.
I'd suggest to start by reviewing official changelogs and release notes to determine the affected parts of your project.
What's New in Spring Framework 5.x might be a good starting point.
Especially watch out for removed features and APIs.
There also is a Spring Integration 4.3 to 5.0 Migration Guide.
while upgrading to Spring 4.2.7 i faced below two issues
Get and Delete requests containing ";" and "%" character will fail with 500 response because of the HttpFirewall restrictions. You can refer to below link for solution.
Getting 500 response in Spring 5 when url contains semicolon
Spring 5 needs default password encoder otherwise it will throw below exception
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null
You can refer to below link for solution.
Spring Security 5 : There is no PasswordEncoder mapped for the id "null"
In our Spring boot application, we have set a versioned migrations in the db.migrations resource folder
V1_0__create_table.sql
V1_1__apply_roles.sql
R__create_stored_proc.sql
The versioned migrations(V1_0 and V1_1) are run/validated at application start-
up but the repeatable migration (R__) does not seem to triggered at all.
We have an afterMigrate.sql as well, which seems to be triggered.
Could someone help me understand the correct way to trigger repeatable flyway migrations in spring boot?
https://flywaydb.org/getstarted/repeatable
Spring Boot 1.x unfortunately ships with an ancient version of Flyway by default (3.x). Update to either Spring Boot 2.0 RC or simply the newest Flyway version (5.x). Note that if this is an existing app you must migrate to Flyway 4.2.0 first, in order for Flyway's schema history table to be automatically upgraded for you..
Am facing an issue while upgrading spring from 1.2.5 to 4.1.1. With the spring1.2.5 spring was committing all my changes to the dao objects in the table without an explicit update query call. But after the upgrade changes is not getting persisted automatically.
Below is my value for my hibernate.transaction.jta.platform configuration
<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform</prop>
After debugging i found in the transaction interceptor class of spring transaction jar, commitTransactionAfterReturning method is being invoked which is committing all changes in the transaction. But am not able to find a equivalent method in the transaction interceptor class of spring transaction 4.1.1 jar. I do not want do explicit updates for all the changes & I want spring to handle them as it was performing in 1.2.5 version.
Please let me know how to handle the above scenario.