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

Entity using @Id Enum field fails with NumberFormatException on cache hit #3110

Open
martinoneutrino opened this issue Jun 16, 2023 · 0 comments

Comments

@martinoneutrino
Copy link

Expected behavior

Finder.byId should return the entity on a cache hit for entities where the @Id field is an Enum (mapped using @DbEnumValue/@EnumValue).

Actual behavior

           java.lang.NumberFormatException: For input string: "Approved"
        at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.base/java.lang.Integer.parseInt(Integer.java:652)
        at java.base/java.lang.Integer.parseInt(Integer.java:770)
        at io.ebeaninternal.server.type.EnumToDbIntegerMap.getBeanValue(EnumToDbIntegerMap.java:40)
        at io.ebeaninternal.server.type.ScalarTypeEnumWithMapping.toBeanType(ScalarTypeEnumWithMapping.java:86)
        at io.ebeaninternal.server.deploy.id.IdBinderSimple.convertId(IdBinderSimple.java:236)
        at io.ebeaninternal.server.deploy.BeanDescriptor.convertId(BeanDescriptor.java:2150)
        at io.ebeaninternal.server.deploy.BeanDescriptorCacheHelp.loadBeanDirect(BeanDescriptorCacheHelp.java:630)
        at io.ebeaninternal.server.deploy.BeanDescriptorCacheHelp.loadBean(BeanDescriptorCacheHelp.java:613)
        at io.ebeaninternal.server.deploy.BeanDescriptorCacheHelp.convertToBean(BeanDescriptorCacheHelp.java:604)
        at io.ebeaninternal.server.deploy.BeanDescriptorCacheHelp.beanCacheGetInternal(BeanDescriptorCacheHelp.java:587)
        at io.ebeaninternal.server.deploy.BeanDescriptorCacheHelp.beanCacheGet(BeanDescriptorCacheHelp.java:566)
        at io.ebeaninternal.server.deploy.BeanDescriptor.cacheBeanGet(BeanDescriptor.java:1295)
        at io.ebeaninternal.server.core.DefaultServer.findIdCheckPersistenceContextAndCache(DefaultServer.java:1014)
        at io.ebeaninternal.server.core.DefaultServer.findId(DefaultServer.java:1041)
        at io.ebeaninternal.server.core.DefaultServer.find(DefaultServer.java:945)
        at io.ebeaninternal.server.core.DefaultServer.find(DefaultServer.java:935)
        at io.ebean.Finder.byId(Finder.java:159)

Steps to reproduce

Updated base-example code at https://github.com/martinoneutrino/examples. This uses release 13.11.0, but error encountered in at least 13.18.0.

Basically:
In the Cached entity class:

public class ProductStatus extends Model {

  public static final ProductStatusFinder find = new ProductStatusFinder();

  @Id
  Status id;

  public enum Status {
    @EnumValue("1")
    Created,
    @EnumValue("2")
    Approved,
    @EnumValue("3")
    Deleted;
  }
}

Call the entity with:

    ProductStatus productStatus = ProductStatus.find.byId(ProductStatus.Status.Approved);
    // the second call fails
    productStatus = ProductStatus.find.byId(ProductStatus.Status.Approved);
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