jpa getresultslist column index exception

85 Views Asked by At

Hello even after I perused Stack Overflow and other sites I have yet to address the problem. I would think it's a configuration issue but both persistence.xml and tomee.xml files seem perfectly fine.

The issue seems to be this line:

  returnList = mapToDtoList(getEntityManager().createNativeQuery("SELECT * FROM map_category_content_type", entityClass).getResultList());

It is generating a "Column index out of range exception 0 < 1" In most cases this is due to an errant index. But in my case, since I never reference an index directly at all (the "magic" is supposed to do that for me) I can only blame either configuration or getResultList().

I have hit a brick wall.

Here is the exception and context. *I am not allowed to post images (not enough "reputation points") but I can assure you that the stack trace is identical to the one found here: Getting column index out of range, 0 < 1

persistence.java code:

  @Stateless
  @TransactionAttribute(TransactionAttributeType.REQUIRED)  
  public class CategoriesAndContentTypesMapPersistence extends  AbstractPersistenceService<CategoriesAndContentTypesMap,  CategoriesAndContentTypesMapDto, Integer> {

  public List<CategoriesAndContentTypesMapDto>    getCategoriesAndContentTypes() {

List<CategoriesAndContentTypesMapDto> returnList;   


try {
  returnList = mapToDtoList(getEntityManager().createNativeQuery("SELECT * FROM map_category_content_type", entityClass).getResultList());
} catch (Exception e) {
  System.out.println("---> "+e);
  throw new PersistenceException(e, this.getClass());
}
return returnList;

}

}

The caller code:

@Inject
private CategoriesAndContentTypesMapPersistence catContPersistence;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

  int categoryID         = 0;
  String categoryName    = "";
  int categorySortOrder  = 0;
  int contentTypeID      = 0;
  String contentTypeName = "";
  int contentTypeSortOrder  = 0;
  int contentTypeRequired   = 0;
  int contentTypeVisibility = 0;

  Map<Integer, String> categoriesContentTypes = new LinkedHashMap<Integer, String>();  
  List<CategoriesAndContentTypesMapDto> dbCatsConts = catContPersistence.getCategoriesAndContentTypes();    

  for (CategoriesAndContentTypesMapDto catCotItem : dbCatsConts) {
    categoryID   = catCotItem.getCategoryId();
    categoryName = catCotItem.getCategoryName();     
    categorySortOrder = catCotItem.getCategorySortOrder();  
    contentTypeID     = catCotItem.getContentTypeId();  
    contentTypeName   = catCotItem.getContentTypeName();  
    contentTypeSortOrder  = catCotItem.getContentTypeSortOrder();  
    contentTypeRequired   = catCotItem.getContentTypeRequired();  
    contentTypeVisibility = catCotItem.getContentTypeVisible();  

I suspect my problem is something along these lines: Getting column index out of range, 0 < 1 but the conf files look fine and were working.

Any advice is greatly appreciated.

1

There are 1 best solutions below

0
On

Nevermind. I didn't have a "managed bean" among other architectural EJB/JSF/... necessities. Thanks all!