Isaac Vásquez (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=627d288...
) *commented* on HHH-16697 (
https://hibernate.atlassian.net/browse/HHH-16697?atlOrigin=eyJpIjoiNmFmZG...
)
Re: AGGREGATE FUNCTIONS in createNativeQuery doExtract integer insted of BigDecimals. (
https://hibernate.atlassian.net/browse/HHH-16697?atlOrigin=eyJpIjoiNmFmZG...
)
If anyone is getting this error, this is a workarround (waiting for the final fix), modify
the getExtractor to check if it is a real Integer or is Float/Double based on String (yes
i know…, dont blame).
@Override
public <X> ValueExtractor<X> getExtractor( final JavaType<X>
javaType) {
return new BasicExtractor<>(javaType, this ) {
@Override
@SuppressWarnings( "unchecked" )
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options)
throws SQLException {
if (isDouble(rs, paramIndex)) {
return (X) FloatJavaType.INSTANCE.wrap(rs.getFloat(paramIndex),
options);
} else {
return javaType.wrap(rs.getInt(paramIndex), options);
}
}
@Override
@SuppressWarnings( "unchecked" )
protected X doExtract(CallableStatement statement, int index, WrapperOptions
options) throws SQLException {
if (isDouble(statement, index)) {
return (X) FloatJavaType.INSTANCE.wrap(statement.getFloat(index),
options);
} else {
return javaType.wrap(statement.getInt(index), options);
}
}
@Override
@SuppressWarnings( "unchecked" )
protected X doExtract(CallableStatement statement, String name, WrapperOptions
options) throws SQLException {
if (isDouble(statement, name)) {
return (X) FloatJavaType.INSTANCE.wrap(statement.getFloat(name),
options);
} else {
return javaType.wrap(statement.getInt(name), options);
}
}
};
}
private <T, Y> Boolean isDouble(T rs, Y paramIndex) throws SQLException {
String str = "";
if (rs instanceof ResultSet rss) {
if (paramIndex instanceof Integer index) {
str = rss.getString(index);
} else if (paramIndex instanceof String param) {
str = rss.getString(param);
}
} else if (rs instanceof CallableStatement cs) {
if (paramIndex instanceof Integer index) {
str = cs.getString(index);
} else if (paramIndex instanceof String param) {
str = cs.getString(param);
}
}
if (str == null) {
return false;
} else if (str.contains(".")) {
int decimalIndex = str.indexOf(".");
String scale = str.substring(decimalIndex + 1);
return !scale.matches("0+"); // si tiene puros ceros despues del punto,
devuelve false.
} else {
return true;
}
}
(
https://hibernate.atlassian.net/browse/HHH-16697#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16697#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:956085d )