title: Transient Exception using persist() method of JPA.. Doubts in persistence of entities.. Which side to persist?
body: <p>First time I am using the persist() method in a project. With JPA I am using Hibernate as the provider. The case is pretty simple. I have 2 tables</p>
  
  <ol>
  <li>Company - Company_id (PK, a sequence), G_Company_id (Would also be unique)</li>
  <li>CP_Doc - Chronicle_id (PK), Company_id (FK to above Company_id))</li>
  </ol>
  
  <p>Now I have some CP_Docs for some particular company. I have successfully created the entities (working for createNativeQuery, createQuery of JPA). I also have mentioned cascade = CASCADE.ALL for the collection.</p>
  
  <p>For persisting I write the following code.</p>
  
  <pre><code>Company company = new Company();
      company.setGCompanyId(7);
      for(/* Get all docs for a particular company having id = 7 */) {
          CP_Doc cpDoc = new CP_Doc();
          cpDoc.setChronicleId(/* some chronicle id from the loop */);    
          cpDoc.setCompany(company);
          entityManager.persist(cpDoc);
      }
  </code></pre>
  
  <p>The relation between the tables is that one company can have many cp_docs. So CP_Doc table is the owner table. I tried persisting from CP_Doc side. Could I persist from Company Entity side also. Kindly help experts :)</p>