title: How to do many-to-one mapping in a Hibernate hbm file
body: <p>I need to use many to one relationship between two tables while using the spring hibernate integrated program. I have <code>employee.hbm.xml</code> and <code>admin.hbm.xml</code> which has corresponding bean classes.</p>
  
  <p><code>empid</code>  in  <code>employee.hbm.xml</code>  acts as a foreign key in <code>admin.hbm.xml</code> .</p>
  
  <p><strong>employee.hbm.xml</strong></p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="entity.Employee" table="employee"&gt;
  &lt;id name="empid" column="empid" type="java.lang.Integer"&gt;
  &lt;generator class="native"&gt;&lt;/generator&gt;
  
  &lt;/id&gt;
  &lt;property name="empname" column="empname" type="java.lang.String"&gt;&lt;/property&gt;
  &lt;property name="password" column="password" type="java.lang.String"&gt;&lt;/property&gt;
  &lt;property name="designation" column="designation" type="java.lang.String"&gt;&lt;/property&gt;
  &lt;property name="domain" column="domain" type="java.lang.String"&gt;&lt;/property&gt;
  &lt;property name="role" column="role" type="java.lang.String"&gt;&lt;/property&gt;
  &lt;property name="head" column="head" type="java.lang.String"&gt;&lt;/property&gt;
  &lt;property name="specialist" column="specialist" type="java.lang.String"&gt;&lt;/property&gt;
  
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p><strong>admin.hbm.xml</strong></p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="entity.Admin" table="admin"&gt;
  &lt;id name="courseid" column="courseid" type="java.lang.Integer"&gt;
  &lt;generator class="increment"&gt;&lt;/generator&gt;
  &lt;/id&gt;
  &lt;property name="coursename" column="coursename" type="java.lang.String"&gt;&lt;/property&gt;
  &lt;property name="participants" column="participants" type="java.lang.Integer"&gt;&lt;/property&gt;
  &lt;!-- &lt;property name="empid" column="empid" type="java.lang.Integer"/&gt; --&gt;
  &lt;many-to-one name="employee" class="entity.Employee" fetch="select" 
  column="empid" cascade="all"/&gt;
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>while i try to insert to admin table, i get a <code>NullPointerException</code> on field <code>empid</code>. what should i modify to make foreign key constraint between these two <code>hbm</code> files???</p>