Skip to content

UnsupportedOperationException: Binding parameters is not supported for simple statement #37

@robelandro

Description

@robelandro

Description: I am encountering an UnsupportedOperationException when trying to use a ManyToMany relationship with Spring Data R2DBC and the springr2dbcrelationships library.

Description:
I am encountering an UnsupportedOperationException when trying to use a ManyToMany relationship with Spring Data R2DBC and the springr2dbcrelationships library.

Environment:

  • Spring Boot version: 3.4.2
  • R2DBC MySQL driver version: 1.3.1
  • springr2dbcrelationships version: 1.1.0

Code:

PrivilegeRepository.java

@Repository
public interface PrivilegeRepository extends ReactiveCrudRepository<Privilege, Long> {

    @Query("SELECT * FROM privilege WHERE name = :name")
    Mono<Privilege> findByName(String name);
}

Privilege.java

import io.github.joselion.springr2dbcrelationships.annotations.ManyToMany;
import lombok.*;
import org.springframework.data.relational.core.mapping.Table;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
@Table
public class Privilege extends BaseModel {
    private String name;

    @ManyToMany(mappedBy = "privileges")
    private List<Role> roles;
}

PrivilegeService

@Slf4j
@AllArgsConstructor
@Service
public class PrivilegeService {

    private final ModelMapper modelMapper;
    private final RoleRepository roleRepository;
    private final PrivilegeRepository privilegeRepository;

    @Transactional
    public Mono<Privilege>  createPrivilege(String name) {

        return privilegeRepository.findByName(name)
                .switchIfEmpty(Mono.defer(() -> {
                    Privilege privilege = Privilege.builder()
                            .name(name)
                            .build();
                    return privilegeRepository.save(privilege);
                }));
    }

}

AppSeeder.java

import java.util.List;
import java.util.Set;

@Slf4j
@Component
public class AppSeeder implements ApplicationListener<ContextRefreshedEvent> {

    private final UserService userService;
    private final RoleService roleService;
    private final PrivilegeService privilegeService;
    private boolean alreadySetup = false;

    public AppSeeder(UserService userService, RoleService roleService, PrivilegeService privilegeService) {
        this.userService = userService;
        this.roleService = roleService;
        this.privilegeService = privilegeService;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        try {

            if (alreadySetup)
                return;

            Privilege readPrivilege = privilegeService.createPrivilege(PrivilegeEnum.READ_PRIVILEGE.name()).block();
            Privilege writePrivilege = privilegeService.createPrivilege(PrivilegeEnum.WRITE_PRIVILEGE.name()).block();


        } catch (Exception e) {
            log.error("Error seeding data", e);
        }
        alreadySetup = true;

    }

}

Error:

2025-02-20T11:09:22.808+03:00 ERROR 18692 --- [USSDPush] [  restartedMain] com.company.ussdpush.boot.AppSeeder   : Error seeding data

java.lang.UnsupportedOperationException: Binding parameters is not supported for simple statement
    at io.asyncer.r2dbc.mysql.SimpleStatementSupport.bind(SimpleStatementSupport.java:48) ~[r2dbc-mysql-1.3.1.jar:1.3.1]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Assembly trace from producer [reactor.core.publisher.FluxError] :

Error has been observed at the following site(s):
    *___________Flux.usingWhen ⇢ at org.springframework.r2dbc.core.DefaultDatabaseClient.inConnectionMany(DefaultDatabaseClient.java:144)
    |_         Flux.onErrorMap ⇢ at org.springframework.r2dbc.core.DefaultDatabaseClient.inConnectionMany(DefaultDatabaseClient.java:156)
    |_      Flux.singleOrEmpty ⇢ at org.springframework.r2dbc.core.DefaultFetchSpec.one(DefaultFetchSpec.java:62)
    |_         Mono.onErrorMap ⇢ at org.springframework.r2dbc.core.DefaultFetchSpec.one(DefaultFetchSpec.java:63)
    |_             Mono.filter ⇢ at io.github.joselion.springr2dbcrelationships.processors.ManyToManyProcessor.findJoinTable(ManyToManyProcessor.java:264)

Steps to Reproduce:

  1. Create a Spring Boot application with Spring Data R2DBC and the springr2dbcrelationships library.
  2. Define a ManyToMany relationship between Privilege and Role entities.
  3. Attempt to seed data using the AppSeeder class.

Expected Behavior:
The ManyToMany relationship should be processed without encountering an UnsupportedOperationException.

Actual Behavior:
An UnsupportedOperationException is thrown when attempting to bind parameters in a simple statement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions