-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: NonUniqueObjectException in Hibernate
PostPosted: Thu Jun 25, 2015 9:42 am 
Newbie

Joined: Thu Jun 25, 2015 9:33 am
Posts: 1
I need 2 lists in my main Hibernate object: one for layouts and one for items. A layout may contain any item from main object, even if it's used by another layouts.

I use following POJO:

Code:
public class MyProject {
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;

    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @JoinColumn(name = "myProject_Id")
    @OrderColumn(name="items_index")
    private List<MyItem> items = new ArrayList<>();

    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @JoinColumn(name = "myProject_Id")
    @OrderColumn(name="itemsLayout_index")
    private List<MyLayout> layouts = new ArrayList<>();
}

public class MyItem {
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;

    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @JoinColumn(name = MyItem_Id")
    @OrderColumn(name="subitem_index")
    private List<MySubItem> subitems = new ArrayList<>();
}

public class MyLayout {
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;

    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @JoinColumn(name = MyLayout_Id")
    @OrderColumn(name="layout_index")
    private List<MyItem> items = new ArrayList<>();
}


But it causes NonUniqueObjectException during saving MyLayout elems, because of subitems.

Is there any way to make such a structure without link objects?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.