Hibernate:避免将null绑定到@Embeddable属性中的参数

时间:2012-07-10 08:23:52

标签: java hibernate embeddable

Hibernate场景:

@Embeddable
public class CompositeKey...{
  private String keyPart1;  
  private String keyPart2;
}

public class Entity{
  @Embedded
  private CompositeKey cKey;
  ...
}

现在使用cKey运行它时,只有keyPart1和keyPart2 == null的值我得到一个“绑定null到参数n”将null绑定到keyPart2。

我可以避免这种情况,并且让hibernate生成一个只包含实际值的参数的SQL并省略null值吗?

所以而不是

where keyPart1 = ? and keyPart2 = ?

我只想要

where keyPart1 = ?

如果cKey.keyPart2 == null

提前致谢...

./ CJ

0 个答案:

没有答案