-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Similar to EJB-59 & HHH-1538 - sum(v) should return Long
PostPosted: Thu Mar 02, 2006 3:40 pm 
Beginner
Beginner

Joined: Mon Jan 09, 2006 3:05 pm
Posts: 24
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 8:20 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Thanks for pointing that out. I've updated HHH-1538

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.