2012-09-10 34 views
3

當使用填充調用與bean的空值屬性時,SQLUpdateClause有問題。它只是從生成的更新SQL中跳過空值屬性,而不是將相應的字段設置爲NULL。Querydsl更新子句填充跳過bean空值屬性

例子:

public class Bean { 

    private Long id; 

    private String value; 

    private String value2; 

    ... 
} 

Bean bean = ... 

bean.setValue(null); 
bean.setValue("value2"); 

SQLUpdateClause update = new SQLUpdateClause(connection, dialect, qBean); 

update.populate(bean).where(qBean.id.eq(...)).execute(); 

會產生SQL:

update bean set value2 = 'value2' where bean.id = ... 

相反的期望:

update bean set value = null, value2 = 'value2' where bean.id = ... 

任何幫助這裏? ......請

回答

7

選中時querydsl源代碼,找到了解決辦法:

... 
update.populate(bean, DefaultMapper.WITH_NULL_BINDINGS) 
     .where(qBean.id.eq(...)) 
     .execute(); 
... 

希望它可以幫助別人