I have the code:
Code:
@Override
public SQLQueriesResult execute(SQLQueries action, ExecutionContext context) throws ActionException {
Session session = null;
index_grid = 0;
Integer count = 0;
Integer offset = action.getLoadConfig().getOffset();
Integer limit = offset + action.getLoadConfig().getLimit();
List<SQLRecord> records = new ArrayList<SQLRecord>();
try {
session = sessionFactory.openSession();
String sql = null;
if (action.isLiveGrid()) {
sql = liveGridSQL(action.getSql(), limit, offset);
} else {
sql = action.getSql();
}
SQLQuery query = session.createSQLQuery(sql);
List<MetaDataFieldConfigSQL> columns = SQLToolsImpl.getColumnFromSQL(session, sql);
for (int i = 0; i < columns.size(); i++) {
query.addScalar(columns.get(i).getFieldName());
}
Iterator<Object[]> result = query.list().iterator();
while (result.hasNext()) {
[b]Object[] type = (Object[]) result.next(); -- this error[/b]
System.out.println(type);
}
/*
for (int i = 0; i < result.size(); i++) {
SQLRecord sqlRecord = new SQLRecord();
sqlRecord.addField("INDEX_GRID", ++index_grid);
for (int j = 0; j < columns.size(); j++) {
sqlRecord.addField(columns.get(j).getFieldName().toUpperCase(),
getFieldValue(columns.get(j).getFieldType(), result.get(j)));
System.out.println(result.size());
}
records.add(sqlRecord);
}
*/
if (!action.isLiveGrid()) {
count = records.size();
}
} catch (JSQLParserException e) {
e.printStackTrace();
} finally {
session.close();
}
return new SQLQueriesResult(
new PagingLoadResultBean<SQLRecord>(records, records.size(), action.getLoadConfig().getOffset()),
count);
}
Why does hibernate return 'String' instead of Object []?
Error:
Code:
[ERROR] Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;
[ERROR] at pl.cba.lukaszbaczek.webmuseum.gui.gxt.widgets.sqlGrid.server.data.SQLQueriesHandler.execute(SQLQueriesHandler.java:74)
[ERROR] at pl.cba.lukaszbaczek.webmuseum.gui.gxt.widgets.sqlGrid.server.data.SQLQueriesHandler.execute(SQLQueriesHandler.java:26)
[ERROR] at com.gwtplatform.dispatch.rpc.server.AbstractDispatchImpl.doExecute(AbstractDispatchImpl.java:154)
[ERROR] ... 43 more
[ERROR]
Hibernate Version is 5.1.0.Final