i have below code snippet in dao
String GET_CUSTOMER="SELECT * from customer where custName=:custName" Session session = getHibernateUtil().getSession(); SQLQuery query = session.createSQLQuery(GET_CUSTOMER); query.setParameter("custName", custName); query.setResultTransformer(Transformers .aliasToBean(Customer.class)); Customer custData = (Customer) query .uniqueResult();//line
Customer table has some int columns for which some values as null. Now at line1 i get error Null value was assigned to a property of primitive type setter of Customer.Address
Is there a way in hibernate/query/Transformer to convert the null values to 0 automatically? I have just mentioned one table i.e customer but there are various joined table which contains int value as null in various columns so i do not want to handle in query for each table.
UPDATE:-Customer is not Hibernate entity. It pojo with instance fields of int type
Customer table has some int columns for which some values as null.
In that case I’d recommend making them
fields instead. While you could
probably get Hibernate to coalesce
(although possibly not in an easy global manner), it’s not really mapping your data effectively – why would you want to lose information like that?