-->
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: how to share a collection between 2 entities ?
PostPosted: Wed Jul 17, 2013 11:50 am 
Newbie

Joined: Tue Jul 16, 2013 9:09 am
Posts: 3
Hello,

I'm working with hibernate and I've got the following exception :

Code:
org.springframework.orm.hibernate4.HibernateSystemException: Found shared references to a collection


Indeed, I'm trying to put in a collection (Set<LocString> label) of my entity (type 'Attribut') the same collection of another entity (same type of entity). I really want datas to be the same (same ids, same everything). I would like ton point on same rows in database and same datas in cache. But, I don't know how to do to not have this exception. When I try to save my Entity I always have the previous exception. How can I do to have my both entities pointing on the same collection of LocString (see next code)

Here are my entities

Code:
@Entity
@Table(name="T_ATTRIBUT")
public class Attribut implements Serializable{

   private static final long serialVersionUID = -2364367529355309198L;

   private long id;
   
   private Set<LocString> label = new HashSet<LocString>(0);

   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name="ID")
   public long getId() {
      return id;
   }

   public void setId(long id) {
      this.id = id;
   }

   @ManyToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
   public Set<LocString> getLabel() {
      return label;
   }

   public void setLabel(Set<LocString> label) {
      this.label = label;
   }
...


and about the locString entity :

Code:
public class LocString implements Serializable {

   private static final long serialVersionUID = -3384318618274464353L;

   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name="ID")
   private long id;
   
   @Column(name="LOCALE")
   private String locale;
   
   @Column(name="VALUE")
   private String value;

...



Thank you very much for your help

Clement


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.