title: How to perform the OneToMany Hibernate mapping when reverse reference is just an id attribute, not full reference
body: <p>Let me be more specific, it was hard to describe this in the title.</p>
  
  <p>I have a class called Bucket, which has a map to a series of Labels. The Bucket class has an id attribute. The class Label doesn't have a reference back to Bucket, instead it has a bucketId field which contains the id of the owning bucket. This was necessary to avoid circular references (Bucket to Label and back Label to Bucket) in order to allow the Bucket objects to be converted to JSON notation.</p>
  
  <p>My Bucket class looks like this:</p>
  
  <pre><code>@Entity(name="Bucket")
  @Table(name = "BUCKETS")
  public class Bucket implements Serializable {
  
      @Id @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "BUCKET_ID")
      protected long id;
  
      /*
       * Map of labels indexed by the label name. I'm not sure this mapping is correct!
       */
      @ElementCollection
      @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
      @MapKeyColumn(name="LABEL_NAME")
      private Map&lt;String, Label&gt; labels = new HashMap&lt;String, Label&gt;();
  
      ...
  
  }
  </code></pre>
  
  <p>and the Label class looks like this:</p>
  
  <pre><code>@Entity(name="Label")
  @Table(name = "LABELS")
  public class Label implements Serializable {
      @Id @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "LABEL_ID")
      protected long id;
  
      /*
       * How do I map this? It should point to the id of the Bucket instance that has
       * this label in its "labels" map
       */
      protected long bucketId;
  
  
      @Column(name = "LABEL_NAME", length=250, nullable=false)
      private String name;
  
      ...
  
  }
  </code></pre>
  
  <p>If I could have a Bucket reference in the Label, I would map it as a @OneToMany and then in the Buckets class I would map as @ManyToOne(mappedBy="bucket"), but I don't have that reference, just the id pointing back.</p>
  
  <p><strong>Does anyone knows how do I map this?</strong></p>
  
  <p>Thank you!
  Eduardo</p>