public void testJointPrefetchSQLTemplate() throws Exception {
createTestData("testJointPrefetch1");
// correctly naming columns is the key..
SQLTemplate q = new SQLTemplate(
Artist.class,
"SELECT distinct "
+ "#result('ESTIMATED_PRICE' 'BigDecimal' '' 'paintingArray.ESTIMATED_PRICE'), "
+ "#result('PAINTING_TITLE' 'String' '' 'paintingArray.PAINTING_TITLE'), "
+ "#result('GALLERY_ID' 'int' '' 'paintingArray.GALLERY_ID'), "
+ "#result('PAINTING_ID' 'int' '' 'paintingArray.PAINTING_ID'), "
+ "#result('ARTIST_NAME' 'String'), "
+ "#result('DATE_OF_BIRTH' 'java.util.Date'), "
+ "#result('t0.ARTIST_ID' 'int' '' 'ARTIST_ID') "
+ "FROM ARTIST t0, PAINTING t1 "
+ "WHERE t0.ARTIST_ID = t1.ARTIST_ID");
PrefetchTreeNode prefetch = q.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY);
assertEquals(
"Default semantics for SQLTemplate is assumed to be joint.",
PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS,
prefetch.getSemantics());
q.setFetchingDataRows(false);
DataContext context = createDataContext();
List objects = context.performQuery(q);