Map<String, Object> options = query.getOptions();
Query q = null;
if (query.isNamed()) {
throw new QueryException("Hibernate dont support named queries");
} else if (query.isNativeSQL()) {
if ((ConditionUtils.containsKey(options, Constants.OPTION_TARGET_ENTITY))) {
Object targetEntity = options.get(Constants.OPTION_TARGET_ENTITY);
if (targetEntity instanceof Class) {
SQLQuery sq = session.createSQLQuery(query.getQuery());
sq.addEntity((Class) targetEntity);
q = sq;
} else if (targetEntity instanceof String) {
try {
SQLQuery sq = session.createSQLQuery(query.getQuery());
sq.addEntity(Class.forName((String) targetEntity));
q = sq;
} catch (ClassNotFoundException e) {
throw new QueryException(e);
}
} else {
throw new QueryException("Invalid option[" + Constants.OPTION_TARGET_ENTITY + "] " + targetEntity);
}
} else {
q = session.createSQLQuery(query.getQuery());
}
} else {