emi*_*lly 3 java sql hibernate
我在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
Run Code Online (Sandbox Code Playgroud)
Customer表有一些int列,其中一些值为null.现在在line1我得到错误Null值被分配给Customer.Address的原始类型setter的属性
在hibernate/query/Transformer中有没有办法自动将空值转换为0?我刚刚提到了一个表即客户,但是有各种连接表,其中包含各种列中的int值为null,因此我不想在每个表的查询中处理.
更新: -客户不是Hibernate实体.它与int类型的实例字段pojo
Customer表有一些int列,其中一些值为null.
在那种情况下,我建议Integer改为制作字段.虽然你可能可能会得到休眠凝聚NULL到0(尽管可能不是一件容易的全球方式),它是不是真的有效映射你的数据-为什么你会不想失去这样的消息?