HibernateTemplate findByExample does not return results

I am trying to use Hibernate QBE (in fact, Spring HibernateTemplate.findByExample ()) to return a list of users by their username. I use the "known good" value to search (username "JOHN.SMITH" exists in the database).

Unfortunately, I am not getting any results. Below is the unit test.

@Test public void testQueryByExample() { User qbeUser = new User(); qbeUser.setUsername("JOHN.SMITH"); List<User> userList = userDao.queryByExample(qbeUser); Assert.notNull(userList); Assert.isTrue(userList.size() > 0, "List of returned users must not be 0"); } 

The queryByExample () method is defined in the general DAO:

 @SuppressWarnings("unchecked") public List<T> queryByExample(T obj) { return getHibernateTemplate().findByExample(obj); } 

Is there any special configuration required for QBE to work?

+4
source share
2 answers

It was pure stupidity on my part.

The classes used as examples contained some int and boolean (primitives) in them. Since these default values ​​are 0 and false, requests were not executed.

+7
source

you need to pass the spring configuration file, otherwise how will it get the connection and pool information. Use @ annotation to load the spring file above the class declaration.

0
source

All Articles