How to query an extended entity
Posted: Fri Jan 17, 2014 7:37 am
Hello,
I have extended ProdutImpl to SeaProductImpl and added two String fields. Admin and Site work well with this extension.
I need now to query the Product table on those two fields.
I tried to extend ProductDaoImpl into SeaProductDaoImpl and add a new query method like this but already the line in bold fails. Can you give any hint how to do correctly ?
public Product readProductByCompuzzId(String compuzzId, String cAccount) {
if (compuzzId == null || "".equals(compuzzId) || cAccount==null || "".equals(cAccount)) {
return null;
}
TypedQuery<SeaProductImpl> query = em.createNamedQuery("SEA_READ_PRODUCTS_BY_NAME", SeaProductImpl.class);
query.setParameter("compuzzProduct_UID", compuzzId);
query.setParameter("compuzzCaccount_UID", cAccount);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
List<SeaProductImpl> resultList=null;
try {
resultList = query.getResultList();
} catch (Exception e) {
System.out.println("exception reading SeaProductImpl");
}
if (resultList == null) {
System.out.println("result list is empty");
return null;
} else {
return query.getResultList().get(0);
}
return null;
}
}
Thank you for any help.
I have extended ProdutImpl to SeaProductImpl and added two String fields. Admin and Site work well with this extension.
I need now to query the Product table on those two fields.
I tried to extend ProductDaoImpl into SeaProductDaoImpl and add a new query method like this but already the line in bold fails. Can you give any hint how to do correctly ?
public Product readProductByCompuzzId(String compuzzId, String cAccount) {
if (compuzzId == null || "".equals(compuzzId) || cAccount==null || "".equals(cAccount)) {
return null;
}
TypedQuery<SeaProductImpl> query = em.createNamedQuery("SEA_READ_PRODUCTS_BY_NAME", SeaProductImpl.class);
query.setParameter("compuzzProduct_UID", compuzzId);
query.setParameter("compuzzCaccount_UID", cAccount);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
List<SeaProductImpl> resultList=null;
try {
resultList = query.getResultList();
} catch (Exception e) {
System.out.println("exception reading SeaProductImpl");
}
if (resultList == null) {
System.out.println("result list is empty");
return null;
} else {
return query.getResultList().get(0);
}
return null;
}
}
Thank you for any help.