findAll() method is giving the empty result set in Hibernate
12,042
I can't see any issues with that, assuming the entity name is accurate and data is present, but did you try the short notation already?
Query query = getSession().createQuery("FROM " + persistentClass.getSimpleName());
I find it better to read for simple 'get all' queries as you don't need any aliases if only one entity is returned.
Author by
ExCode
Updated on June 05, 2022Comments
-
ExCode almost 2 years
In hibernate I used
findById()
andfindAll()
in Dao layer.findById()
method working as I expected, butfindAll()
always returns empty result set,I still couldn't figure out the reason, any one could help me to solve this issue,Note: There is no exception, returns only empty list
Here is my code
Find All method
public List<T> findAll() { Query query = getSession().createQuery("SELECT obj FROM " + persistentClass.getSimpleName() + " obj"); return query.list() }
Find by Id method
public T findById(Long id) { T result = (T) getSession().get(getPersistentClass(), id); return result; }
getSession method
protected Session getSession() { if (session == null) session = tenantBasedSessionFactory.getTenantBasedSession("tenantId"); // throw new IllegalStateException("Session has not been set on DAO before usage"); return session; }
Thank you in advance Cheers