title: About Mapping Object To Database Using Hibernate
body: <p>Hello guys i am new to hibernate. while i was surfing stack overflow for hibernate related topics i found this </p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/8347350/need-clarification-about-mapping-objects-to-database-annotations-and-one-to-ma">Need clarification about mapping objects to database, annotations, and one to many relationships</a></p>
  </blockquote>
  
  <p>after reading the solution i was a bit confused and started building the exact scenario to understand the actual mechanism behind many to one, where i used oracle 11g database. When i am running my project hibernate is generating the tables and FK relations automatically but in the time of inserting data it facing this problem (which is obvious)</p>
  
  <pre><code>WARN: HHH000437: Attempting to save one or more entities that have a non-nullable association with an unsaved transient entity. The unsaved transient entity must be saved in an operation prior to saving these dependent entities.
  Unsaved transient entity: ([com.entity.Authorization#0])
  Dependent entities: ([[com.entity.Job#1]])
  
  WARN: HHH000437: Attempting to save one or more entities that have a non-nullable association with an unsaved transient entity. The unsaved transient entity must be saved in an operation prior to saving these dependent entities.
      Unsaved transient entity: ([com.entity.JobFilteration#0])
      Dependent entities: ([[com.entity.Job#1]])
      Non-nullable association(s): ([com.entity.Job.jobfilteration])
  </code></pre>
  
  <p>i did exactly what was the solution of the above topic I have mentioned, I am posting my entity class(s) Please help me to solve this</p>
  
  <p><strong>Class Job</strong></p>
  
  <pre><code>@Entity
  @Table(name="JOB")
  public class Job implements Serializable {
      @Id 
      @SequenceGenerator(name="person_seq", sequenceName="SEQ_PERSON",initialValue=1,allocationSize=1)
      @GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="person_seq")
      @Column(name="JOB_SERIAL")
      private int id;
  
      @Column(name="JOB_CATAGORY",nullable=false,length=200,unique=true)
      private String catagory;
  
  
      @ManyToOne(fetch=FetchType.LAZY)
      @JoinColumn (name="JOB_AUTHID", nullable = false, updatable = false, insertable = false)
      private Authorization authorization;
  
      @ManyToOne(fetch=FetchType.LAZY)
      @JoinColumn (name="JOB_JOBFILTERID", nullable = false, updatable = false, insertable = false)
      private JobFilteration jobfilteration;
  </code></pre>
  
  <p><strong>Class JobFilteration</strong></p>
  
  <pre><code>@Entity
  @Table(name="JOB_FILTERATION")
  public class JobFilteration implements Serializable {
      @Id 
      @SequenceGenerator(name="person_seq", sequenceName="SEQ_PERSON",initialValue=1,allocationSize=1)
      @GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="person_seq")
      @Column(name="FILTER_SERIAL")
      private int id;
  
      @Column(name="FILTERNAME",nullable=false,length=200)
      private String filtername;
  </code></pre>
  
  <p><strong>Class Authorization</strong></p>
  
  <pre><code>@Entity
  @Table(name="AUTHORIZATION")
  public class Authorization implements Serializable {
      @Id 
      @SequenceGenerator(name="person_seq", sequenceName="SEQ_PERSON",initialValue=1,allocationSize=1)
      @GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="person_seq")
      @Column(name="AUTH_ID")
      private int id;
  
      @Column(name="AUTHORISEDBY",nullable=false,length=200)
      private String authorisedby;
  </code></pre>
  
  <p>and for inserting the data i wrote a method  <code>public void insertToDB(Job job)</code>(I used same sequence for three classes to save time) and then </p>
  
  <pre><code>JoBDao jobdao= new JoBDao();
  Job job= null;
  Authorization auth = null;
  JobFilteration jfilter = null;
  
  try{
  job= new Job();
  
  auth = new Authorization();
      auth.setAuthorisedby("SOMEPERSON");
  
  jfilter = new JobFilteration();
      jfilter.setFiltername("JEE");
  
  job.setCatagory("PERMANENT");
  job.setAuthorization(auth);
  job.setJobfilteration(jfilter);
  
  
  jobdao.addPersonandCard(job);
  </code></pre>
  
  <p>I think the exception occurred because the data was inserted in the job table before inserting in the other table(s). Please help me to find out  what am I missing?</p>