my2iu / Jinq

LINQ-style queries for Java 8
Other
659 stars 71 forks source link

issues on enums? #67

Open georgemoralis opened 7 years ago

georgemoralis commented 7 years ago

I have the following on my entity

private Integer eiditype;

public SpeciesType getEiditype() { return SpeciesType.getType(this.eiditype); }

public void setEiditype(SpeciesType eiditype) {

    if (eiditype == null) {
        this.eiditype = null;
    } else {
        this.eiditype = eiditype.getId();
    }
}

When i use the following query

stream = stream.where(p -> p.getEiditype() == SpeciesType.SERVICE);

i get the following error

Caused by: org.jinq.rebased.org.objectweb.asm.tree.analysis.AnalyzerException: Unknown method prototype/eidi/EidiEntity:getEiditype()LprototypeERP/model/enums/SpeciesType; encountered

I tried with ids as well

stream = stream.where(p -> p.getEiditype().getId() == SpeciesType.SERVICE.getId());

but not working either , any idea?

georgemoralis commented 7 years ago

btw my whole enum implementation was based on that

http://blog.chris-ritchie.com/2013/09/mapping-enums-with-fixed-id-in-jpa.html

my2iu commented 7 years ago

I think in this case, JPA/Hibernate/EclipseLink sees the field as being an integer, not an enum. (The enum stuff in this situation is just a wrapper that the JPA layer doesn't see.) So Jinq expects the accessor method to return an integer as well. You would need to create a separate getter that uses an integer, and use that in your queries so that Jinq creates code that is consistent with what JPA/Hibernate/EclipseLink is expecting.

public int getEiditype() {
   return this.eiditype;
}

Jinq only supports enums when you use normal JPA enums

georgemoralis commented 7 years ago

yah i changed it to proper jpa enum to handle it properly without 2 getters and now it appears to work right thank you for your efford and help!