Spock and Grails: Why gone wrong?

L

luigi1982

Guest
Hi at all

this is my integration test in Grails 2.5.1: Inside the setup() there is:

Code:
Role roleAdmin = new Role(RoleType.ROLE_ADMIN.name(), 1000).save(failOnError: true, flush: true)
    Role roleMerchant = new Role(RoleType.ROLE_MERCHANT.name(), 1).save(failOnError: true, flush: true)
    Role roleProvider = new Role(RoleType.ROLE_PROVIDER.name(), 2).save(failOnError: true, flush: true)
    Role roleUser = new Role(RoleType.ROLE_USER.name(), 3).save(failOnError: true, flush: true)

    RoleGroup roleGroupAdmin = new RoleGroup(RoleGroupType.ADMIN.name()).save(failOnError: true, flush: true)
    RoleGroup roleGroupCustomer = new RoleGroup(RoleGroupType.CUSTOMERS.name()).save(failOnError: true, flush: true)
    RoleGroup roleGroupUsers = new RoleGroup(RoleGroupType.USERS.name()).save(failOnError: true, flush: true)

    RoleGroupRole.create(roleGroupAdmin, roleAdmin, true)
    RoleGroupRole.create(roleGroupCustomer, roleMerchant, true)
    RoleGroupRole.create(roleGroupCustomer, roleProvider, true)
    RoleGroupRole.create(roleGroupUsers, roleUser, true)


When run I have this error:

Code:
    | Error 2015-12-21 11:14:04,994 [main] ERROR spi.SqlExceptionHelper  - Cannot add or update a child row: a foreign key constraint fails (`pi_test`.`role_group_role`, CONSTRAINT `FK_dxc3snhixkg9qn3c46p6hyjli` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`))

The classes `User`, `Role` and `RoleGroupRole` are standard classes generated by s2-quickstart from `Spring Security Plugin`.

Why this happens? I flush every insert, but seems that cannot find the id of roles and `RoleGroupRole`.

Thanks for all!

Luis
 
Top