Java jpa getresultslist列索引异常
你好,即使在我仔细阅读了Stack Overflow和其他网站之后,我仍然没有解决这个问题。我认为这是一个配置问题,但persistence.xml和tomee.xml文件似乎都很好 问题似乎是这样的:Java jpa getresultslist列索引异常,java,jpa,ejb,Java,Jpa,Ejb,你好,即使在我仔细阅读了Stack Overflow和其他网站之后,我仍然没有解决这个问题。我认为这是一个配置问题,但persistence.xml和tomee.xml文件似乎都很好 问题似乎是这样的: returnList = mapToDtoList(getEntityManager().createNativeQuery("SELECT * FROM map_category_content_type", entityClass).getResultList()); 它正在生成“列索
returnList = mapToDtoList(getEntityManager().createNativeQuery("SELECT * FROM map_category_content_type", entityClass).getResultList());
它正在生成“列索引超出范围异常0<1”
在大多数情况下,这是由于索引错误造成的。但是在我的例子中,因为我从来没有直接引用过索引(魔法应该为我这样做),所以我只能怪配置或getResultList()
我撞到了砖墙
这里是例外和上下文。
*我不允许发布图像(没有足够的“信誉点”),但我可以向您保证堆栈跟踪与此处找到的跟踪相同:
正在获取列索引超出范围,0<1
persistence.java代码:
@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;
@无状态
@TransactionAttribute(TransactionAttributeType.REQUIRED)
公共类Categories和ContentTypesMappersistence扩展了AbstractPersistenceService{
公共列表getCategoriesAndContentTypes(){
列表返回列表;
试一试{
returnList=MapToToList(getEntityManager().createNativeQuery(“从地图\类别\内容\类型,entityClass.getResultList()中选择*);
}捕获(例外e){
System.out.println(“-->”+e);
抛出新的PersistenceException(e,this.getClass());
}
退货清单;
}
}
调用方代码:
@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();
@Inject
私有类别和内容类型最大耐受性catContPersistence;
受保护的void doGet(HttpServletRequest请求,HttpServletResponse响应)抛出ServletException,IOException{
int categoryID=0;
字符串categoryName=“”;
int categorySortOrder=0;
int contentTypeID=0;
字符串contentTypeName=“”;
int contentTypeSortOrder=0;
int contentTypeRequired=0;
int contentTypeVisibility=0;
Map categoriesContentTypes=新建LinkedHashMap();
List dbCatsConts=catContPersistence.getCategoriesAndContentTypes();
用于(类别和内容类型更新到CATCOTS项目:dbCatsConts){
categoryID=catCotItem.getCategoryId();
categoryName=catCotItem.getCategoryName();
categorySortOrder=catCotItem.getCategorySortOrder();
contentTypeID=catCotItem.getContentTypeId();
contentTypeName=catCotItem.getContentTypeName();
contentTypeSortOrder=catCotItem.getContentTypeSortOrder();
contentTypeRequired=catCotItem.getContentTypeRequired();
contentTypeVisibility=catCotItem.getContentTypeVisibile();
我怀疑我的问题是这样的:
正在获取列索引超出范围,0<1
但是conf文件看起来很好,并且工作正常
非常感谢您的建议。别客气。
在其他架构EJB/JSF/…必需品中,我没有“托管bean”。
谢谢大家!为什么要使用本机查询而不是JPQL查询?异常的完整堆栈跟踪是什么?我发现JPQL有点…简洁。如果我不是绝对“必须”使用它,我会完全避免它。