I have a problem that might be a different manifiscation of EJB-59 & HHH-1538 or an entirely new problem.
Hibernate 3.1.1, Annotations 3.1B8, EntityManager 3.1B6
I've an entity property that maps to an Oracle Number(4,0) which the hibernate reverse engineering tool correctly assigned the "short" java type.
Code:
@Column(name="N_READS", unique=false, nullable=false, insertable=true, updatable=true, precision=4, scale=0)
public short getNumberOfReads() {
return this.numberOfReads;
}
However, if I write a EJB-QL query that uses the SUM() aggregate operator to sum many of these numberOfReads values, it can easily exceed what can be stored in a short. However, hibernate is trying to retrieve it as a short, giving:
Code:
Caused by: java.sql.SQLException: Numeric Overflow
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleStatement.getShortValue(OracleStatement.java:4414)
at oracle.jdbc.driver.OracleResultSetImpl.getShort(OracleResultSetImpl.java:517)
at oracle.jdbc.driver.OracleResultSet.getShort(OracleResultSet.java:1578)
at org.hibernate.type.ShortType.get(ShortType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.loader.hql.QueryLoader.getResultColumnOrRow(QueryLoader.java:326)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:595)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1127)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:749)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:44)
If I change the type of the property in the entity code to be a long, the query works fine. Thus, it seems that the type of the property is determining the way the query results are interpreted.
This is similar to the original COUNT() problem, because count returns not just an integer, but sometimes other Number subclasses, which also correspond to the java type of the entity property.
The original problem is easily worked around by doing something like
Code:
count = ((Number)query.getSingleResult()).longValue();
but this latest issue is forcing me to change the java types of my properties, which makes ripples throughout my code.
--keenan