views:

153

answers:

1

I'm mapping a set of attributes to my entity using @CollectionOfElements. 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,