首页 > 解决方案 > MySQL - TypedQuery 忽略构造函数的空值

问题描述

对于 TypedQuery:

TypedQuery<MyObject> query = em.createQuery(
        "SELECT new " + MyObject.class.getName() + "(o.id, o.value1, o.value2, o.value3, z, t.id, possiblyNull, o.either, o.or) FROM Table1 AS t " +
                "JOIN t.objects AS o JOIN o.zValue AS z JOIN o.child AS b JOIN b.parent AS possiblyNull " +
                "WHERE t.id IN(:table1Ids)", MyObject.class);
query.setParameter("table1Ids", table1Ids); 
return query.resultsList();

resultsList始终为空。对于某些值,该属性possiblyNull可能为空。属性o.eithero.orOneToMany与表 1 的(OneToMany相关)对象的关系。

如果我尝试一次获取每个值(fe 表示 TypedQueryo.either而不是完整的构造函数,我会得到所有不是的o.either结果null)它可以工作。有没有办法为每个获取所有构造函数条目o.id,而不管某些其他属性是否存在null

标签: mysqldatabaseselect

解决方案


推荐阅读