'hibernate session.createQuery() keeps getting an ArrayIndexOutOfBoundsException
I'm new to hibernate and currently struggling with setting up a Rest-API.
When I try to fetch all objects, it works fine and I also can search for an object by its ID. But when I try to use an HQL query (even a simple one like 'from CustomObject'), it won't work.
I somehow managed to get (seamingly) sessionFactory to work, so I can get a Session object for creation of HQL-Queries. But at the moment, when session.createQuery() is called, I always get an ArrayIndexOutOfBoundsException.
Here's my function, where the problem is happening:
public List<CustomObject> findByHQL() {
Configuration conf = new Configuration().configure();
SessionFactory sessionFactory = conf.buildSessionFactory();
Session session = sessionFactory.openSession();
String hqlQueryString = "from com.blackfake.hibernate_query_test.orm.CustomObject o";
Query<CustomObject> hqlQuery = session.createQuery(hqlQueryString, CustomObject.class);
// NativeQuery<CustomObject> sqlQuery = session.createSQLQuery("select id, name, price from objects");
return hqlQuery.list();
}
Session and SessionFactory are from org.hibernate package
Configuration is from org.hibernate.cfg
what I find even more confusing, is, that the createSQLQuery() method does work without any problem …
Maybe I should mention, that my DB is a PostgreSQL ;)
The Error:
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.hibernate.internal.AbstractSharedSessionContract.resultClassChecking(AbstractSharedSessionContract.java:862) ~[hibernate-core-5.6.7.Final.jar:5.6.7.Final]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:849) ~[hibernate-core-5.6.7.Final.jar:5.6.7.Final]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:114) ~[hibernate-core-5.6.7.Final.jar:5.6.7.Final]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
