I have a column that potentially has some bad data, and I can't clear it, so I need to check for a null or empty row. I am making a request for Hibernation Criteria, so I have the following that is returning incorrectly right now:
Session session = getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Criteria myCriteria = session.createCriteria(Object); ... myCriteria.add(Restrictions.or(Restrictions.isNull("stringColumn"), Restrictions.eq("stringColumn", ""))); List<Objects> list = myCriteria.list();
I cannot get it to correctly return the expected results. Since in the experiment, I changed the second restriction on reading:
Restrictions.eq("stringColumn", "''")
And it started to return the expected results, so hibernate incorrectly translates my empty string (e.g. ") into an empty SQL string (e.g. ''), or am I just doing it wrong?
sql hibernate criteria
Stephen
source share