1 Risposta
- Più recenti
- Maggior numero di voti
- Maggior numero di commenti
0
Answering my own question here for anyone that is looking to use Spring Data with the Athena JDBC driver.
So, it turns out that limit NULL
was indeed the issue, and the parameterized limit
field is not supported with Hibernate/Athena JDBC/MySQLDialect. I was able to workaround the issue by extending the MySQLDialect
class, and implementing my own "limit handler" to fill in the limit/offset fields with the real values instead of a parameterized value. Here is an example of the SQL Dialect that works with hibernate and the JDBC driver:
package com.acme.athena;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.pagination.AbstractLimitHandler;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.LimitHelper;
import org.hibernate.engine.spi.RowSelection;
import java.sql.PreparedStatement;
public class AthenaMySQLDialect extends MySQLDialect {
private static final LimitHandler LIMIT_HANDLER = new AbstractLimitHandler() {
@Override
public String processSql(String sql, RowSelection selection) {
final boolean hasOffset = LimitHelper.hasFirstRow( selection );
String _sql = sql + " limit %d".formatted(selection.getMaxRows());
if (hasOffset) {
_sql += " offset %d".formatted(selection.getFirstRow());
}
return _sql;
}
@Override
public boolean supportsLimit() {
return true;
}
@Override
public int bindLimitParametersAtEndOfQuery(RowSelection selection, PreparedStatement statement, int index) {
return 0;
}
};
@Override
public boolean supportsLimit() {
return true;
}
@Override
public LimitHandler getLimitHandler() {
return LIMIT_HANDLER;
}
@Override
public String getLimitString(String sql, boolean hasOffset) {
return sql + (hasOffset ? " limit ? offset ?" : " limit ?");
}
}
Once you have this dialect, you can set the hibernate driver with a property:
spring:
jpa:
properties:
hibernate:
dialect: "com.acme.athena.AthenaMySQLDialect"
ddl-auto: validate
con risposta 10 mesi fa
Contenuto pertinente
- AWS UFFICIALEAggiornata 2 anni fa
- AWS UFFICIALEAggiornata 3 anni fa