I have a table with an Enum type attribute mapped like this:
@Enumerated(EnumType.ORDINAL)
@Column(name = "status")
private Enums.Status status;
Where the Enums.Status is
public enum Status {
CHECKED(1),
DISABLED(2),
INACTIVE(3);
int id;
// constructor + getter
}
And the column status from the database is stored as type int4
I am querying the table with the following HQL:
Query q = session.createQuery(" from Users where status=:account");
query.setParameter("account", Enums.Status.CHECKED);
List<Users> users = query.list();
The above code works fine on my testing server, but when on the production server it throws the following exception:
org.hibernate.exception.DataException: Bad value for type int : t
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:134)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:108)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at com.sun.proxy.$Proxy30.getInt(Unknown Source)
at org.hibernate.type.EnumType$OrdinalEnumValueMapper.getValue(EnumType.java:358)
at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:105)
at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:127)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:106)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2873)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1668)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1600)
at org.hibernate.loader.Loader.getRow(Loader.java:1500)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:712)
at org.hibernate.loader.Loader.processResultSet(Loader.java:940)
at org.hibernate.loader.Loader.doQuery(Loader.java:910)
I tried replacing the enum parameter with its .ordinal() value, but received another exception. I tried looking up the differences between the testing server and the production server, but they both use the same java version, hibernate library, datatypes for the table and table content.
Has anyone ever encountered any similar issue or has any idea how it could be fixed?