简体   繁体   中英

Hibernate select query

I'm using the below query to fetch details from 2 tables as mentioned and then store the result in a list

Query selectEntry = em.createQuery("select b.affStyle,b.actualAffService " +
    "from SdHeaders a, SdAffectedServices b " +
    "where a.id = b.id AND a.sdClass = 'NET' AND b.actualAffService IS NOT NULL " +
    "AND b.itemType = :itemType " +
    "group by b.affStyle, b.actualAffService");                     

selectEntry.setParameter("itemType",ob.getItemType());
result=selectEntry.getResultList();

While executing this, I'm getting the below error and the list also should be populated with 2 values but it's not.

Subquery result[[Ljava.lang.Object;@2b4a90f0]
Result string[[Ljava.lang.Object;@2b4a90f0]
[Ljava.lang.Object;@2b4a90f0
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
    at java.util.ArrayList.rangeCheck(ArrayList.java:657)
    at java.util.ArrayList.get(ArrayList.java:433)

When I run the query in SQL developer it gives me the proper result. Can someone please help?

selectEntry.setParameter("itemType",ob.getItemType());

This might be probable cause. ob.getItemType() data type and itemType data type in the DB are not matching. Can you correct it and retry?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM