I am using an SQLQuery to load some entities from a view. The view is not mapped -- the entities are already mapped to another table.
Here is my code:
Code:
public class SampleDAO extends DAO<Sample,UUID> {
...
@SuppressWarnings("unchecked")
public List<Sample> findByAlliance (Alliance alliance) {
return getSession().createSQLQuery("select * from [samples_with_alliances] where [alliance_id]=?")
.addEntity(Sample.class)
.setEntity(0, alliance)
.list();
}
}
Sample and Alliance are both mapped to their own tables in an XML mapping document.
[samples_with_alliances] is a database view (MSSQL) that returns all the columns required to load a Sample, plus an additional alliance_id column for searching by Alliance.
The above code is working exactly as expected. However, I don't feel comfortable using T-SQL flavored SQLQueries in my Hibernate DAO's. Is there a way to do this using HQL and a Query (or Criteria)?
Thanks!