6

I am using the below hibernate code to fetch the data from 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 CrfEmailDataBean class, I have declared a private String crfEmailTypeCd; field which is null in database. Because of null, it is not setting the record in return list. If I go and enter a value inside the field in database, it fetches.

I tried running the query directly on sql database, the query formed is correct and fetches all the data.

Why it is not fetching that record? and how can I resolve this?

9
  • Post the CrfEmailDataBean class as well Commented Aug 12, 2016 at 17:36
  • 5
    Not sure why people are upvoting this. Without the entity mapping nobody will be able to answer this question. Commented Aug 16, 2016 at 20:31
  • 1
    Hi all , I had recieved an answer which I am not able to see now . Based on his suggestion , I checked my hbm file . I had included the said field as composite-id in my hbm file . Now it is working .Thanks Commented Aug 17, 2016 at 7:11
  • 1
    What about CAMPN_NBR, campNbr, getSessionFactory(), CrfEmailDataBean.class? Provide the code, please. Which version of Hibernate do you use? Commented Aug 18, 2016 at 14:59
  • 3
    You should post your answer instead of adding it to question. Then it will be easier to other to find it. Commented Aug 18, 2016 at 15:18

1 Answer 1

0

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

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

if hibernate database ready null, when converters of the Hibernate generator a error

  • solution for this never user primitive type
  • Or define de default value for properties
  • Each other possibility your date not null, this value white
  • white is different of the null
  • make a test put conditions Restrictions.isNotNull.
  • make other test put conditions Restrictions.isNull.
  • other test make a method receive int, call send one Integer null

first item

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);
    } }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.