Master-Detail Table Management and Transaction Handling in Permission Systems

Resolving PageHelper Integration Issues

When integrating pagination using PageHelper in a Spring project, a compatibility issue may arise between different library versions. The error manifests as a NoSuchMethodError related to MyBatis reflection utilities.

The root cause typically involves version mismatches between PageHelper and MyBatis. To resolve this, remove manual Spring integration configurations and adopt the Spring Boot starter approach instead.

Add the following dependency to pom.xml:

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.10</version>
</dependency>

Configure PageHelper properties in application.properties:

pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql

Remove any previous MyBatis configuration files related to pagination plugins.

Master-Detail Table Page Implementation

Database relationships include one-to-one, one-to-many, and many-to-many patterns. In permistion managemant systems, typical relationships include user-role and role-permission mappings, implemented through junction tables.

The user experience for managing these relationships follows a specific pattern. When viewing a user, a dialog displays currently assigned roles. Users can add new roles through a secondary dialog showing unassigned roles, or remove existing role assignments. This bidirectional management approach provides intuitive control over associations.

The implementation reuses existing table management pages for displaying roles in dialogs, reducing code duplication. The same pattern applies to role-permission relationship management with minimal modifications.

Transaction Management Implementation

Master-detail relationships introduce data integrity requirements. When deleting a master record, associated detail records must also be removed to maintain referential integrity. For example, deleting a user requires removing corresponding entries from the user-role juncsion table.

Enabling Transaction Management

Enable global transaction support in the main application class using the @EnableTransactionManagement annotation:

@ComponentScan(basePackages = {"com.example.*"})
@SpringBootApplication
@EnableTransactionManagement 
public class ManageApplication {
    public static void main(String[] args) {
        SpringApplication.run(ManageApplication.class, args);
    }
}

Declaring Transactions

Apply the @Transactional annotation to service methods requiring transactional behavior. The following example demonstrates deleting a user along with associated role mappings:

@Override
@Transactional(propagation = Propagation.REQUIRED)
public Boolean deleteUserRecord(String userId) throws Exception {
    String[] idArray = userId.split(",");
    if (idArray.length > 0) {
        userMapper.deleteUser(idArray);
        for (String currentId : idArray) {
            removeRoleAssociations(currentId, "");
            throw new RuntimeException("Transaction test exception");
        }
    }
    return true;
}

When testing with a user who has existing role associations, the operation will fail as expected when the RuntimeException is thrown, demonstrating proper transaction rollback behavior.

Tags: spring-boot MyBatis pagehelper transactions master-detail

Posted on Sun, 07 Jun 2026 16:04:56 +0000 by robot43298