Metaclass not found

Hi,
Am getting the following error “java.lang.IllegalArgumentException: MetaClass not found for RoleAssignmentEntity
at io.jmix.core.metamodel.model.impl.SessionImpl.getClass(SessionImpl.java:43)
at io.jmix.core.impl.MetadataImpl.getClass(MetadataImpl.java:102)”
while trying to retrieve assigned roles for a user.
Any leads on how to resolve this?

Regards,

Charles

If you need roles for current user look at getRoleNames method from example

Thanks for your response. I want to get the roles assigned for a different user other than the authenticated user. Can this method be applied? If yes, an example would really go a long way.

Please, provide snippet of your code. Its really hard to guess what you do and what you want.

List roleAssignmentList = dataManager.load(RoleAssignmentEntity.class)
.query(“select e from RoleAssignmentEntity e where e.username=:userName”)
.parameter(“userName”, user.getUsername())
.list();

Find the code snippet above

Hi,

most likely your JQPL statement is wrong. The name of the entity is not the class name, but the configured name of the @Entity annotation. For the RoleAssignmentEntity, you can see the value looks like this:

@Table(name = "SEC_ROLE_ASSIGNMENT")
@Entity(name = "sec_RoleAssignmentEntity")
@JmixEntity
@SystemLevel
public class RoleAssignmentEntity implements Serializable {

Therefore your query needs to look like this:

List roleAssignmentList = dataManager.load(RoleAssignmentEntity.class)
.query(“select e from sec_RoleAssignmentEntity e where e.username=:userName”)
.parameter(“userName”, user.getUsername())
.list();

Besides that, you might also just use the APIs from the Framework, instead of using the underlying primitives. E.g. there are the two APIs RoleAssignmentRepository::getAssignmentsByUsername and DatabaseRoleAssignmentProvider which will probably serve your needs.

Cheers
Mario

3 Likes