hibernate - JPA Query: java.lang.ClassCastException: [Enum] cannot be cast to java.lang.Enum -
i need help...
i building application , using jpa queries there wrong enum types.
i have this.
public enum schedulingstatus { skipped, pending_confirmation, confirmed, sent, processing, cancelled, finished, finished_with_errors, not_confirmed_in_server }
then class farmirrigationscheduling.java many other fields , important one:
@column @enumerated(enumtype.ordinal) private schedulingstatus status;
and trying query:
typedquery<farmirrigationscheduling> query = getentitymanager().createquery( "from farmirrigationscheduling farm = :farm , status not in :statuscollection order calculated desc", farmirrigationscheduling.class); query.setparameter("farm", farm); schedulingstatus[] status = new schedulingstatus[] { schedulingstatus.finished, schedulingstatus.finished_with_errors, schedulingstatus.cancelled }; query.setparameter("statuscollection", status); return getsingleresult(query);
i getting following exception:
caused by: java.lang.classcastexception: [lau.com.agrichem.addams.server.model.enums.schedulingstatus; cannot cast java.lang.enum @ org.hibernate.type.enumtype.nullsafeset(enumtype.java:239) @ org.hibernate.type.customtype.nullsafeset(customtype.java:170) @ org.hibernate.param.namedparameterspecification.bind(namedparameterspecification.java:53) @ org.hibernate.loader.hql.queryloader.bindparametervalues(queryloader.java:628) @ org.hibernate.loader.loader.preparequerystatement(loader.java:1956) @ org.hibernate.loader.loader.executequerystatement(loader.java:1909) @ org.hibernate.loader.loader.executequerystatement(loader.java:1887) @ org.hibernate.loader.loader.doquery(loader.java:932) @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:349) @ org.hibernate.loader.loader.dolist(loader.java:2615) @ org.hibernate.loader.loader.dolist(loader.java:2598) @ org.hibernate.loader.loader.listignorequerycache(loader.java:2430) @ org.hibernate.loader.loader.list(loader.java:2425) @ org.hibernate.loader.hql.queryloader.list(queryloader.java:502) @ org.hibernate.hql.internal.ast.querytranslatorimpl.list(querytranslatorimpl.java:371) @ org.hibernate.engine.query.spi.hqlqueryplan.performlist(hqlqueryplan.java:216) @ org.hibernate.internal.sessionimpl.list(sessionimpl.java:1458) @ org.hibernate.query.internal.abstractproducedquery.dolist(abstractproducedquery.java:1426) @ org.hibernate.query.internal.abstractproducedquery.list(abstractproducedquery.java:1398) @ org.hibernate.query.getresultlist(query.java:417) @ au.com.agrichem.addams.server.model.repositories.base.hibernatedaoimpl.getsingleresult(hibernatedaoimpl.java:100) @ au.com.agrichem.addams.server.model.repositories.impl.schedulingsdaoimpl.getcurrentschedulingbyfarm(schedulingsdaoimpl.java:126) @ au.com.agrichem.addams.server.services.impl.schedulingsserviceimpl.getscheduling(schedulingsserviceimpl.java:68) ... 116 more
i don't why cannot cast enum java.lang.enum. before using hibernate , hql , working, changed having issue.
does know why , how can fix it??
thanks lot in advance!!
this has nothing enums.
you must pass in list, not array:
// create list: list<schedulingstatus> statuses = arrays.aslist(schedulingstatus.finished, schedulingstatus.finished_with_errors, schedulingstatus.cancelled); query.setparameter("statuscollection", statuses);
Comments
Post a Comment