title: Hibernate Association
body: <p>i am using hibernate. i have two tables : Job and Company.</p>
  
  <p>Company.hbm.xml is :</p>
  
  <p>
  
  </p>
  
  <pre><code>&lt;class name="com.jobs.admin.data.Company" table="S_COMPANY"&gt;
      &lt;id name="companyKid" column="COMPANY_KID" type="integer"&gt;
          &lt;generator class="sequence"&gt;
              &lt;param name="sequence"&gt;company_sequence&lt;/param&gt;
          &lt;/generator&gt;
      &lt;/id&gt;
      &lt;property name="companyName" column="COMPANY_NAME" length="200" type="string" unique="true"/&gt;
      &lt;property name="companyDesc" column="COMPANY_DESC" type="string" length="1000" unique="true"  /&gt;
      &lt;property name="companySName" column="COMPANY_SNAME" type="string" length="100"/&gt;
      &lt;property name="companyMail" column="COMPANY_MAIL" type="string" length="200"/&gt;
      &lt;property name="companyPhone" column="COMPANY_PHONE" type="string" length="200"/&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p></p>
  
  <p>My Job.hbm.xml is :</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;hibernate-mapping&gt;
  
      &lt;class name="com.jobs.admin.data.Job" table="S_JOBS"&gt;
          &lt;id name="jobKid" column="JOB_KID" type="integer"&gt;
              &lt;generator class="sequence"&gt;
                  &lt;param name="sequence"&gt;job_sequence&lt;/param&gt;
              &lt;/generator&gt;
          &lt;/id&gt;
          &lt;property name="jobTitle" column="JOB_TITLE" type="string"/&gt;
          &lt;property name="jobDesc" column="JOB_DESC" type="string"&gt;&lt;/property&gt;
  &lt;!--        &lt;property name="jobCompany" column="JOB_COMPANY" type="integer"&gt;&lt;/property&gt;--&gt;
          &lt;property name="jobCity" column="JOB_CITY" type="integer"&gt;&lt;/property&gt;
          &lt;property name="jobExp" column="JOB_EXP" type="integer"&gt;&lt;/property&gt;
          &lt;property name="jobCat" column="JOB_CAT" type="integer"&gt;&lt;/property&gt;
          &lt;property name="jobStartDate" column="JOB_STARTDATE" type="string"&gt;&lt;/property&gt;
          &lt;property name="jobEndDate" column="JOB_ENDDATE" type="string"&gt;&lt;/property&gt;
          &lt;many-to-one name="jobCompany" class="com.jobs.admin.data.Company" column="JOB_COMPANY" property-ref="companyKid" &gt;&lt;/many-to-one&gt;
  
      &lt;/class&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>This is my method code which is joing these tables</p>
  
  <pre><code> List&lt;com.jobs.admin.data.JobCat&gt; jobCat= null;
          db_session= HibernateSessionFactory.getSessionFactory().openSession();
          transaction=null;
          try{
              transaction = db_session.beginTransaction();
              jobCat = db_session.createQuery("from Job as job inner join job.jobCompany as company").list();
              transaction.commit();
          }
          catch (HibernateException e) {
              transaction.rollback();
              e.printStackTrace();
              } finally {
              db_session.close();
              }
          return jobCat;
  </code></pre>
  
  <p>When i am running it is giving me following exception :</p>
  
  <pre><code>java.lang.NullPointerException
      at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1662)
      at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:641)
      at org.hibernate.type.EntityType.resolve(EntityType.java:415)
      at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139)
      at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
      at org.hibernate.loader.Loader.doQuery(Loader.java:752)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
      at org.hibernate.loader.Loader.doList(Loader.java:2232)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
      at org.hibernate.loader.Loader.list(Loader.java:2124)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
      at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
      at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)
      at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
      at com.jobs.admin.service.JobImpl.getJobs(JobImpl.java:91)
      at com.jobs.admin.controller.JobController.showViewJobs(JobController.java:64)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
      at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
      at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
      at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:619)
  </code></pre>
  
  <p>please suggest me , what is my error ?</p>