综合编程

The null value was assigned to a primitive type property during query execution in hibernat…

微信扫一扫,分享到朋友圈

The null value was assigned to a primitive type property during query execution in hibernat…
0

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 Integer
fields instead. While you could
probably get Hibernate to coalesce NULL
to 0
(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?

阅读原文...


Hello, buddy!

Episode 010 - The Automate or Die Special - The Evil Tester Show

上一篇

Bystack — Blockchain as a Service (BaaS) Platform

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
The null value was assigned to a primitive type property during query execution in hibernat…

长按储存图像,分享给朋友