title: JPA releations between OneToMany And ManyToOne
body: <p>I'm new to JPA and trying to do relations between two tables like this:</p>
  
  <p>This is the main class object <code>XParserLinks</code>:</p>
  
  <pre><code>    private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "link_id")
      private Integer linkId;
      @OneToMany(mappedBy = "xParserLink", targetEntity = XLinksMedia.class, cascade = CascadeType.ALL)
      private List&lt;XLinksMedia&gt; fotos;
      ...
  </code></pre>
  
  <p>This is the object class <code>XLinksMedia</code> </p>
  
  <pre><code>public class XLinksMedia implements Serializable {
      private static final long serialVersionUID = 1L;
      @EmbeddedId
      protected XLinksMediaPK xLinksMediaPK;
      @ManyToOne @JoinColumn(name = "link_id")
      private XParserLinks xParserLink;
  </code></pre>
  
  <p>and <code>XLinksMediaPK</code></p>
  
  <pre><code>@Embeddable
  public class XLinksMediaPK implements Serializable {
      @Basic(optional = false)
      @Column(name = "link_id", insertable = false, updatable = false)
      private int linkId;
      @Basic(optional = false)
      @Column(name = "image")
      private String image;
  </code></pre>
  
  <p>Are these relations correct? Because when I want to add new <code>XLinksMedia</code> objects in <code>fotos</code> list, I get <code>LinkId = 0</code>, but I know that <code>LinkId</code> is not <code>0</code>, I know that <code>LinkId</code> variable have a value. </p>
  
  <p>Here's how I try to set <code>fotos</code> variable in <code>XParseLinks</code> class (<code>preke</code>: is <code>XParseLinks</code> object witch have his primary key <code>LinkId</code>):</p>
  
  <pre><code>XLinksMedia foto = new XLinksMedia();
  foto.setXLinksMediaPK(new XLinksMediaPK());
  
  foto.setxParserLink(preke);
  foto.getXLinksMediaPK().setImage(e.attr("src"));
  
  preke.getFotos().add(foto);
  </code></pre>