Guillaume VON TOKARSKI (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5a9c818...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNGQ5MTY1ZDRh...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16241?atlOrigin=eyJpIjoiNGQ5MT...
) HHH-16241 (
https://hibernate.atlassian.net/browse/HHH-16241?atlOrigin=eyJpIjoiNGQ5MT...
) Unable to use MAX and MIN function on type with AttributeConverter (
https://hibernate.atlassian.net/browse/HHH-16241?atlOrigin=eyJpIjoiNGQ5MT...
)
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Created: 28/Feb/2023 10:02 AM
Priority: Major Reporter: Guillaume VON TOKARSKI (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5a9c818...
)
The model has java.time.YearMonth attributes being mapped to integers on the DB (MariaDB)
Here is how it was used:
@Convert(converter = YearMonthConverter.class)
@Column(name = "month" , nullable = false )
private YearMonth month;
And here is the converter class (based on Jakarta now):
public class YearMonthConverter implements AttributeConverter<YearMonth, Integer >
{
@Override
public Integer convertToDatabaseColumn(YearMonth attribute) {
return attribute == null ? null : (attribute.getYear() * 100) +
attribute.getMonth().getValue();
}
@Override
public YearMonth convertToEntityAttribute( Integer dbData) {
return dbData == null ? null : YearMonth.of(dbData / 100, dbData % 100);
}
}
I’ve got a MAX() query on this column which fails with the following error:
org.hibernate.QueryException: Parameter 1 of function max() has type COMPARABLE, but
argument is of type java.time.YearMonth
It’s worth noticing that the ORM is able to read/write this column from the DB, it only
fails to run functions like MIN or MAX.
The debugging took me to a section of the code in ArgumentTypesValidator where the code
considers that the node type YearMonth is incompatible with the FunctionParameterType
COMPARABLE.
Let me know if there is anything else that I can provide.
(
https://hibernate.atlassian.net/browse/HHH-16241#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16241#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#100217- sha1:65be9f2 )