hibernate @CollectionOfElements 未持久化

发布于 2024-10-03 00:23:27 字数 1431 浏览 1 评论 0原文

您好,

到目前为止我对 Hibernate 的使用非常满意。最近我似乎无法使用注释来持久化 @CollectionOfElements 。

我正在保存 Estate 类的对象,其中包含 RoomGroups 地图,如下所示:

@javax.persistence.MapKey(name = "code")
@Cascade(value = {CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE})
@OneToMany(mappedBy = "estate")
@org.hibernate.annotations.OrderBy(clause = "code ASC")
private Map<String, RoomsGroup> roomGroups = new HashMap<String, RoomsGroup>();

RoomGroup 已正确保留。 RoomGroup 与 MasterPrice 也有关系

@Cascade(value = {CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE})
@OneToOne(mappedBy = "roomGroup", fetch = FetchType.EAGER)
private MasterPrice prices;

到目前为止,MasterPrice 元素已正确存储在 DB 中。现在 MasterPrice 内部有另一个集合,这个集合似乎永远不会被持久化

@CollectionOfElements (fetch = FetchType.EAGER)
@JoinTable(
  name = "roomgroups_masterprice_items",
  joinColumns = {@JoinColumn(name = "fk_masterpricesID")})
@IndexColumn(name = "position")
private List<MasterPriceItem> dbprices = new ArrayList<MasterPriceItem>();

MasterPriceItem 类是这样定义的,

@Embeddable
public class MasterPriceItem implements Serializable{

我还在 MasterPriceItem 中定义了 equal/hashCode 方法,但似乎 hibernate 永远不会持久化这个集合。我没有遇到任何异常,当我尝试加载它时,它总是显示为 NULL。

我正在使用 hibernate_3.3.1.ga 有什么想法可以尝试吗? MasterPriceItem 类由 hibernate 正确分析[如果我放置的字段不在表中,则会出现错误]

高度赞赏任何帮助。谢谢。

HI,

I am using Hibernate with plenty of satisfaction so far. Lately it seems that I am not able to persist a @CollectionOfElements using annotation.

I am saving an object of class Estate which contains a Map of RoomGroups like here:

@javax.persistence.MapKey(name = "code")
@Cascade(value = {CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE})
@OneToMany(mappedBy = "estate")
@org.hibernate.annotations.OrderBy(clause = "code ASC")
private Map<String, RoomsGroup> roomGroups = new HashMap<String, RoomsGroup>();

The RoomGroup is persisted correctly. And RoomGroup has also the relationship with MasterPrice

@Cascade(value = {CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE})
@OneToOne(mappedBy = "roomGroup", fetch = FetchType.EAGER)
private MasterPrice prices;

So far so good, MasterPrice elements are correctly stored in DB. Now inside MasterPrice there is another collection and this one seems that is never going to be persisted

@CollectionOfElements (fetch = FetchType.EAGER)
@JoinTable(
  name = "roomgroups_masterprice_items",
  joinColumns = {@JoinColumn(name = "fk_masterpricesID")})
@IndexColumn(name = "position")
private List<MasterPriceItem> dbprices = new ArrayList<MasterPriceItem>();

The class MasterPriceItem is defined like this

@Embeddable
public class MasterPriceItem implements Serializable{

I defined also the equal/hashCode methods in the MasterPriceItem but it seems that hibernate is never persisting this one. I do not get any exception and when I try to load it always comes up as NULL.

I am using hibernate_3.3.1.ga any idea that I can try? The class MasterPriceItem is correctly analysed by hibernate [if I put a field that is not in the table, I get an error]

Any help highly appreciated. thx.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文