HIbernate does not output a value where the field has a null value in the database record

I use the sleeping code below to retrieve data from a database.

SessionFactory factory = null; Session session = null; try { factory = getSessionFactory(); session = factory.openSession(); final Criteria criteria = session .createCriteria(CrfEmailDataBean.class); criteria.add(Restrictions.eq(CAMPN_NBR, campNbr)); returnList = criteria.list(); } catch (Exception e) { logger.error(e.getMessage()); throw new DAOException(e); } finally { DBUtil.close(factory, session); } if (logger.isInfoEnabled()) { logger.info(LOG_METHOD_EXIT); } return returnList; } 

Inside the CrfEmailDataBean class I declared a private String crfEmailTypeCd; field private String crfEmailTypeCd; which is null in the database. Due to a null value, it does not set an entry in the return list. If I go and enter the value inside the field in the database, it will be selected.

I tried to execute the query directly in the sql database, the generated query is correct and fetch all the data.

Why is he not retrieving this entry? and how can i solve this?

+7
java hibernate
source share
1 answer

when you use primitive type properties, you must set the default value, the same zero (0) or (a) (..)

 private int number; private int value; private char option; 

if hibernate database ready null when Hibernate generator converters have an error

  • solution for this never primitive user type
  • Or define a default value for properties
  • Every other possibility of your date is not null; this value is white.
  • white is different from zero
  • fulfill the conditions of the test condition. Limitations. Needed.
  • make other conditions of the test condition. Limitations Not.
  • another test make get int method, call send one Integer null

first element

 private Integer number; private Integer value; private Character option; 

last item test

 public class Test{ public static void setInt(int value){ System.out.println(value); } public static void main(String[] args) { Integer testValue=null; Test.setInt(testValue); } } 
0
source share

All Articles