java - Query enum in hibernate throws DataException: Bad value for type int : t -
i have table enum type attribute mapped this:
@enumerated(enumtype.ordinal) @column(name = "status") private enums.status status;
where enums.status is
public enum status { checked(1), disabled(2), inactive(3); int id; // constructor + getter }
and column status database stored type int4
i querying table following hql:
query q = session.createquery(" users status=:account"); query.setparameter("account", enums.status.checked); list<users> users = query.list();
the above code works fine on testing server, when on production server throws following exception:
org.hibernate.exception.dataexception: bad value type int : t @ org.hibernate.exception.internal.sqlstateconversiondelegate.convert(sqlstateconversiondelegate.java:134) @ org.hibernate.exception.internal.standardsqlexceptionconverter.convert(standardsqlexceptionconverter.java:49) @ org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:125) @ org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:110) @ org.hibernate.engine.jdbc.internal.proxy.abstractresultsetproxyhandler.continueinvocation(abstractresultsetproxyhandler.java:108) @ org.hibernate.engine.jdbc.internal.proxy.abstractproxyhandler.invoke(abstractproxyhandler.java:81) @ com.sun.proxy.$proxy30.getint(unknown source) @ org.hibernate.type.enumtype$ordinalenumvaluemapper.getvalue(enumtype.java:358) @ org.hibernate.type.enumtype.nullsafeget(enumtype.java:105) @ org.hibernate.type.customtype.nullsafeget(customtype.java:127) @ org.hibernate.type.abstracttype.hydrate(abstracttype.java:106) @ org.hibernate.persister.entity.abstractentitypersister.hydrate(abstractentitypersister.java:2873) @ org.hibernate.loader.loader.loadfromresultset(loader.java:1668) @ org.hibernate.loader.loader.instancenotyetloaded(loader.java:1600) @ org.hibernate.loader.loader.getrow(loader.java:1500) @ org.hibernate.loader.loader.getrowfromresultset(loader.java:712) @ org.hibernate.loader.loader.processresultset(loader.java:940) @ org.hibernate.loader.loader.doquery(loader.java:910)
i tried replacing enum parameter .ordinal()
value, received exception. tried looking differences between testing server , production server, both use same java version, hibernate library, datatypes table , table content.
has ever encountered similar issue or has idea how fixed?
with java enums, term ordinal
not refer id
property, built in property of enum
class. see javadocs ordinal()
method.
returns ordinal of enumeration constant (its position in enum declaration, initial constant assigned ordinal of zero). programmers have no use method. designed use sophisticated enum-based data structures, such enumset , enummap.
note first ordinal 0 (zero) not 1
don't calling ordinal()
method yourself; let hibernate that.
Comments
Post a Comment