'Custom insert by @Query() on R2dbcRepository method fails silently without an exception ? How can i make this work?
I'm using 'org.springframework.boot:spring-boot-starter-data-r2dbc' and 'org.springframework.boot:spring-boot-starter-webflux'. 3 different datasources (works, following spring.io docs, fine) using a spring repository (R2dbcRepository) to save/insert/update/query 3 different entities into 3 different tables "users" "roles" and "user_roles" (basically trying to convert a blocking api to a non-blocking one). To insert new rows into "user_roles" i configured a custom query
@Transactional
@Modifying
@Query(value="insert into user_roles(userid, roleid) values('?1', '?2')")
Mono<Long> saveRoleidAndUserid(Long userid, List<Long> roleids);
which silently fails (no new rows are inserted without an exception).
inserting with entityTemplate
userEntityTemplate
.getDatabaseClient()
.sql("insert into user_roles(userid, roleid) values('"+userroles.getUserid()+"','"+userroles.getRoleid()+"')")
.fetch()
.rowsUpdated()
.subscribe(x -> logger.info("rows inserted: "+ x.longValue()));
or from postgres (with the same query) works fine.
Also inserting with the same userRepo.save(User user) for "user" objects works fine too.
The role table gets initialzed once (with a couple of roles to query) and also inserting with save () works fine, too.
How can i get the custom insert to work with @Query() annotation ?
Thanks in Advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
