|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.hibernate.dialect.function.AvgFunction
org.hibernate.dialect.function.AvgWithArgumentCastFunction
public class AvgWithArgumentCastFunction
Some databases strictly return the type of the of the aggregation value for AVG which is problematic in the case of averaging integers because the decimals will be dropped. The usual workaround is to cast the integer argument as some form of double/decimal.
A downside to this approach is that we always wrap the avg() argument in a cast even though we may not need or want to. A more full-featured solution would be definingSQLFunction
such that we render based on the first
argument; essentially have SQLFunction
describe the basic metadata about the function and merge the
SQLFunction.getReturnType(org.hibernate.type.Type, org.hibernate.engine.Mapping)
and SQLFunction.render(java.util.List, org.hibernate.engine.SessionFactoryImplementor)
methods into a
Constructor Summary | |
---|---|
AvgWithArgumentCastFunction(java.lang.String castType)
|
Method Summary | |
---|---|
java.lang.String |
render(java.util.List args,
SessionFactoryImplementor factory)
Render the function call as SQL fragment. |
Methods inherited from class org.hibernate.dialect.function.AvgFunction |
---|
getReturnType, hasArguments, hasParenthesesIfNoArguments, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public AvgWithArgumentCastFunction(java.lang.String castType)
Method Detail |
---|
public java.lang.String render(java.util.List args, SessionFactoryImplementor factory) throws QueryException
SQLFunction
render
in interface SQLFunction
render
in class AvgFunction
args
- The function argumentsfactory
- The SessionFactory
QueryException
- Indicates a problem rendering the
function call.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |