开发者

Hibernate Null values for @CollectionOfElements

I'm mapping a set of attributes to my entity using @CollectionOfElements开发者_Python百科. The goal here is to be able to provide a meta data list that can be used in a query to pull specific entries.

I've figured out the mapping and how to run the queries I want. The problem is that hibernate won't persist null values!


    @CollectionOfElements()
    @JoinTable(name = "plan_attribute", joinColumns = @JoinColumn(name = "plan_id"))
    @MapKey(columns = @Column(name = "attribute_name", nullable = false, length = 255))
    @Column(name = "attribute_value", nullable = true, length = 255)
    public Map getAttributes() {
        return attributes;
    }

    public void setAttributes(Map attributes) {
        this.attributes = attributes;
    }

    public void addAttribute(String name, String value) {
        this.attributes.put(name, value);
    }

Eg. object.addAttribute("someName", null); will not be persisted

Anyone have any thoughts on how to accomplish this without implementing a key/value pair entity for the sole purpose of persisting these values?

Regards,


Quoting from the OP comments:

Hibernate 3.3.2.GA, so yes - it looks like that bug applies. I was able to workaround the issue by explicitly setting null values as a '*' character which actually works quite well and fits better than 'null' for my use-cases.

This answer should get this off the list of unanswered questions until a close vote is made.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜