Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:03:05+00:00 2026-06-11T23:03:05+00:00

I have Role entity class: @Entity public class Role extends Model { @Id @Constraints.Required

  • 0

I have Role entity class:

@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
}

In some test I try to find users by role:

List<User> users = User.findByRole(Role.findByRoleName(RoleNameEnum.ADMIN));

where method findByRoleName() is following:

public static List<User> findByRole(Role role) {
    return find.where().eq("role", role).findList();
}

I receive error:

[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)

Does anybody have an idea what might be a problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:03:07+00:00Added an answer on June 11, 2026 at 11:03 pm

    The quickest solution, assuming that you are mapping EnumValue exactly the same as the enum names:

    public enum RoleNameEnum {
        @EnumValue("REGULAR")
        REGULAR,
        @EnumValue("ADMIN")
        ADMIN
    }
    

    Then you can implement the findByRole method as following:

    public static List<User> findByRole(Role role) {
        return find.where().eq("role", role.name()).findList();
    }
    

    where the magic is just using the mapped string value instead of the enum instance for the role name.

    I posted a bug on the ebean issue tracker: http://www.avaje.org/bugdetail-427.html, binder should detect the enum object and interpret it as its mapped value automatically.

    EDIT:

    In case that you need some other mapping than the simple enum value, here it is the utility code to get the value set using the @EnumValue annotation

    public static <T extends Enum<T>> String serialize(T theEnum) {
        try {
            for (Field f : theEnum.getDeclaringClass().getDeclaredFields()) {
                if (theEnum.equals(f.get(theEnum))) {
                    EnumValue enumValue = f.getAnnotation(EnumValue.class);
                    if (enumValue != null)
                        return enumValue.value();
                }
            }
        } catch (Exception e) {
        }
        return null;
    }
    

    Then you can implement findByRole using the serialize method

    public static List<User> findByRole(Role role) {
        return find.where().eq("role", serialize(role)).findList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model called 'UserRoleHolder' like below. @Entity public class UserRoleHolder extends Model
I have two classes, user and role, defined as: public class User : Entity
We have the following two entities with many-to-many association: @Entity public class Role {
I have a simple class Role: @Entity @Table (name = ROLE) public class Role
I have the following (simple) mapping: @Entity public class Role { @OneToMany( fetch =
I have next code in my Entity class class Role { private List<String> tubes;
I have the following entities: public class User { public virtual ICollection<Role> Roles {
I have Doctrine 2.1 entity: /** * @Entity(repositoryClass=Varlab\Model\Repository\UserRepository) * @Table(name=user) */ class User {
Using JPA and Hibernate I have an entity class @Entity @Table(name = "ROLES") public
In my model I have an abstract User class, and multiple subclasses such as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.