我有角色实体类:
@Entity
public class Role extends Model {
@Id
@Constraints.Required
public Integer id;
@Constraints.Required
@Formats.NonEmpty
@Enumerated(EnumType.STRING)
public RoleNameEnum name; // name is enum value
}
在一些测试中,我尝试按角色查找用户:
List<User> users = User.findByRole(Role.findByRoleName(RoleNameEnum.ADMIN));
其中方法findByRoleName()
如下:
public static List<User> findByRole(Role role) {
return find.where().eq("role", role).findList();
}
我收到错误:
[error] Test UserTest.findUsersByRole failed: No ScalarType registered for class models.Role
[error] at com.avaje.ebeaninternal.server.persist.Binder.bindObject(Binder.java:183)
[error] at com.avaje.ebeaninternal.server.query.CQueryPredicates.bind(CQueryPredicates.java:162)
[error] at com.avaje.ebeaninternal.server.query.CQuery.prepareBindExecuteQuery(CQuery.java:413)
[error] at com.avaje.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:198)
[error] at com.avaje.ebeaninternal.server.query.DefaultOrmQueryEngine.findMany(DefaultOrmQueryEngine.java:104)
[error] at com.avaje.ebeaninternal.server.core.OrmQueryRequest.findList(OrmQueryRequest.java:344)
[error] at com.avaje.ebeaninternal.server.core.DefaultServer.findList(DefaultServer.java:1469)
[error] at com.avaje.ebeaninternal.server.querydefn.DefaultOrmQuery.findList(DefaultOrmQuery.java:906)
[error] at com.avaje.ebeaninternal.util.DefaultExpressionList.findList(DefaultExpressionList.java:201)
[error] at models.User.findByRole(User.java:63)
[error] at UserTest$4.run(UserTest.java:62)
[error] at play.test.Helpers.running(Helpers.java:294)
[error] at UserTest.findUsersByRole(UserTest.java:58)
有人知道可能是什么问题吗?