biniam_Ethiopia biniam_Ethiopia - 1 year ago 56
Groovy Question

Grails and Hibernate: Unknown entity: com.mypackage.Role

I have a grails application. I've installed spring security core plugin 2.0 RC2 and I'm creating roles, users and requestmap in BootStrap.groovy
Grails is throwing the following error when I run the app.

ERROR context.GrailsContextLoader - Error initializing the application: Unknown entity: Role

Here is my Role class (generated by the spring security plugin and modified to extend AbstractActivity with is an abstract class that has beforeInsert() method/closure and does some validation).

package com.mypackage

class Role extends AbstractDomain {

String authority

Date dateCreated
Date lastUpdated
User createdBy
User updatedBy

static mapping = {
cache true

static constraints = {
authority blank: false, unique: true

createdBy nullable: true
updatedBy nullable: true


package com.mypackage

import com.mypackage.User

class AbstractDomain implements Serializable {

transient springSecurityService

def beforeInsert() {

if(null != springSecurityService) {

User user = springSecurityService.getCurrentUser()

if(null != user) {

this.createdBy = user



import com.mypackage.Role

class BootStrap {
def init = { servletContext ->
if (Role.findByAuthority('ROLE_ADMIN') == null)
def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
def destroy = {}


grails.plugin.springsecurity.userLookup.userDomainClassName ='com.mypackage.User'
grails.plugin.springsecurity.userLookup.authorityJoinClassName 'com.mypackage.UserRole'
grails.plugin.springsecurity.authority.className = 'com.mypackage.Role'
grails.plugin.springsecurity.requestMap.className = 'com.mypackage.Requestmap'
grails.plugin.springsecurity.securityConfigType = 'Requestmap'

How do I solve the Unknown entity issue?

Answer Source

I found the solution! My AbstractDomain Class which was extended by Role class was in 'src/groovy' folder and I forgot to make it 'abstract'. Then I added the abstract keyword before class, it works like magic. Thanks @mgg for giving me the idea here

So, my AbstractDomain class now looks like

abstract class AbstractDomain implements Serializable {