ebean-orm-deprecated / ebean-querybean

Moved as a module into ebean.git repo
https://ebean.io/docs/query/query-beans
Apache License 2.0
9 stars 3 forks source link

PEnum use name() instead of toString() #10

Closed all-sd closed 8 years ago

all-sd commented 9 years ago

Hi Rob,

using enums in a typequery uses toString() to geht the enum representation. This ist not working if you override the toString() in an enum.

To reproduce:

public enum Type {
        CUSTOMER("Kunde"),
        private final String caption;
        private Type(String caption) {
            this.caption = caption;
        }
        @Override
        public String toString() {
            return caption;
        }
    }

And the Query:

new QCustomer().type.eq(Customer.Type.CUSTOMER).findUnique();
new QCustomer().type.in(Customer.Type.CUSTOMER).findUnique();

Will result in a query where the type="Kunde" and not type="CUSTOMER".

rbygrave commented 9 years ago

This pull request does not look appropriate. The actual bind value depends on how the Enum is mapped and that can be by name, ordinal or a mapped value via @EnumValue. The determination of that bind value happens later (not as part of typequery).

So there will be some other problem but this pull request is not appropriate.

all-sd commented 9 years ago

Ok, no problem. Do you have a hint for me, where I have to search for a better solution?

rbygrave commented 9 years ago

I'll see if there are tests for all 3 forms of enum mapping.

You can try adding: @Enumerated(EnumType.STRING)

Or explicit mapping via @EnumValue ...

public enum Status { @EnumValue("N") NEW, @EnumValue("A") APPROVED, @EnumValue("S") SHIPPED, @EnumValue("C") COMPLETE }

On 30 September 2015 at 09:00, ossd notifications@github.com wrote:

Ok, no problem. Do you have a hint for me, where I have to search for a better solution?

— Reply to this email directly or view it on GitHub https://github.com/ebean-orm/avaje-ebeanorm-typequery/pull/10#issuecomment-144172919 .

all-sd commented 9 years ago

Ok, but there is an @Enumerated on my field:

    @Enumerated(EnumType.STRING)
    private Type type;

Where is the test case? Is there a test case with @Enumerated(EnumType.STRING) and an overridden toString() in the enum?

rbygrave commented 8 years ago

This was logged as https://github.com/ebean-orm/avaje-ebeanorm/issues/580 ... will be fixed in 7.1.2

rbygrave commented 8 years ago

So this merge request is not correct in that the problem was never in the querybean but instead in ebean as per https://github.com/ebean-orm/avaje-ebeanorm/issues/580

Closing.