Hibernate version is 4.3.11 The MySQL Account table is :
Code:
Field Type Null Key
Id int(11) NO PRI
Reference varchar(20) NO UNI
Balance decimal(10,5) NO
Currency varchar(3) NO
Valid tinyint(1) NO
Type varchar(20) YES YES
The AccountDaoImpl method :
Code:
public Map<String, Account> getAccountsByReferences(Collection<String> accountReferences) throws DaoException {
// TODO Auto-generated method stub
if (accountReferences == null || accountReferences.isEmpty()) {
return null;
}
if (accountReferences.size() > Constants.MAX_ACCOUNTS_SIMULT) {
throw new DaoException("Please query " + Constants.MAX_ACCOUNTS_SIMULT + " at a time");
}
String accountByRefSQL = "SELECT new map(acc.reference,acc ) FROM Account acc WHERE acc.reference IN (:accountReferences)";
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
Query query = session.createQuery(accountByRefSQL).setParameterList("accountReferences", accountReferences);
return findMany(query);//Obvious compilation error here
} catch (DaoException daoException) {
log.error("DaoException in AccountDaoImpl.findAccountByReference(...)", daoException);
throw daoException;
} catch (HibernateException e) {
log.error("HibernateException in AccountDaoImpl.findAccountByReference(...)", e);
throw new DaoException(e.getMessage());
} finally {
session.close();
}
}
The findMany() method is in the parent GenericDao :
Code:
public List<T> findMany(Query query) throws DaoException {
try {
List<T> t;
t = (List<T>) query.list();
return t;
} catch (HibernateException hibernateExecption) {
log.error("Hibernate Exception in GenericHibernateDaoImpl.findMany(...)", hibernateExecption);
throw new DaoException(hibernateExecption.getMessage());
} catch (RuntimeException runtimeException) {
log.error("RuntimeException in GenericHibernateDaoImpl.findMany(...)", runtimeException);
throw new DaoException(runtimeException.getMessage());
}
}
There are two questions :
Is my approach/query correct i.e in order with the expectations(return type of the method getAccountsByReferences() ?
What will query actually return(I read somewhere that the Query will return will return a List of Map - I don't understand this) ?