Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composite id #19

Open
eugenio1590 opened this issue May 13, 2019 · 0 comments
Open

Composite id #19

eugenio1590 opened this issue May 13, 2019 · 0 comments

Comments

@eugenio1590
Copy link

I am using the Grails Spring Security core for the security of the web app. And this working with this dependency very well. But I get an error when the primary key is a domain and not a value. I mean a composite primary key. For example:

userRole(meta:[key:['user','role']], user:[email: '[email protected]', domainClass: 'User'], role:[authority: 'ROLE_ADMIN', domainClass: 'Role'])

In this case (using the domain of the Spring Security) the primary key is a composite value that uses the primary key of the user object and the role object. But in the console, I get the following error:

Seed Error Inserting UserRole (user: null, role: null, id: null, version: null)
  - The [role] property of the class [class app.UserRole] can not be null
  - The [user] property of class [class app.UserRole] can not be null

The UserRole class is this:

@GrailsCompileStatic
@ToString(cache=true, includeNames=true, includePackage=false)
class UserRole implements Serializable {

	private static final long serialVersionUID = 1

	User user
	Role role
        
        ......

	static constraints = {
	    user nullable: false
		role nullable: false, validator: { Role r, UserRole ur ->
			if (ur.user?.id) {
				if (UserRole.exists(ur.user.id, r.id)) {
				    return ['userRole.exists']
				}
			}
		}
	}

	static mapping = {
		id composite: ['user', 'role']
		version false
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant