@CollectionOfElements 的 Hibernate Null 值
我使用 @CollectionOfElements 将一组属性映射到我的实体。这里的目标是能够提供一个元数据列表,可在查询中使用该列表来提取特定条目。
我已经弄清楚了映射以及如何运行我想要的查询。问题是休眠不会保留空值!
@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);
}
例如。 object.addAttribute("someName", null);不会被持久化
有人对如何在不实现键/值对实体来实现这一点的唯一目的是持久化这些值有任何想法吗?
问候,
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,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用OP评论:
在进行接近投票之前,这个答案应该将其从未回答的问题列表中删除。
Quoting from the OP comments:
This answer should get this off the list of unanswered questions until a close vote is made.