Hibernate One-To-One mapping issues
<p>I have the following two classes:</p>

<pre><code>public class User {

    private int id;
    private String name;
    private ProteinData proteinData;

    public User(){
        setProteinData(new ProteinData());
    }

    public ProteinData getProteinData() {
        return proteinData;
    }
    public void setProteinData(ProteinData proteinData_) {
        this.proteinData = proteinData_;
        proteinData_.setUser(this);
    }

   // additional getters and setters

}


public class ProteinData {

    private int id;
    private User user;


    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
}
</code></pre>

<p>Mapping files are:</p>

<pre><code>//User
&lt;hibernate-mapping&gt;
   &lt;class name="com.simpleprogrammer.User" table="USERS"&gt;
      &lt;meta attribute="class-description"&gt;
         This class contains the User detail. 
      &lt;/meta&gt;
      &lt;id name="id" type="int"&gt;
         &lt;column name="ID" /&gt;
         &lt;generator class="identity"/&gt;
      &lt;/id&gt;
      &lt;property name="name" type="java.lang.String"&gt;
         &lt;column name="NAME" /&gt;
      &lt;/property&gt;

      &lt;one-to-one name="proteinData" class="com.simpleprogrammer.ProteinData" cascade="save-update"/&gt;
&lt;/hibernate-mapping&gt;

// proteinData
&lt;hibernate-mapping&gt;
   &lt;class name="com.simpleprogrammer.ProteinData" table="PROTEINDATA"&gt;
        &lt;id name="id" type="int"&gt;
            &lt;column name="ID" /&gt;
            &lt;generator class="foreign"&gt;
                &lt;param name="property"&gt;user&lt;/param&gt;
            &lt;/generator&gt;
        &lt;/id&gt;
        &lt;one-to-one name="user" class="com.simpleprogrammer.User" constrained="true"&gt;
        &lt;/one-to-one&gt;
        &lt;property name="total" type="int" column="TOTAL" /&gt;
        &lt;property name="goal" type="int"&gt;
            &lt;column name="GOAL"/&gt;
        &lt;/property&gt;
   &lt;/class&gt;
&lt;/hibernate-mapping&gt;
</code></pre>

<p>Now I when run my application, I get the following errors:</p>

<pre><code>Exception in thread "main" org.hibernate.PropertyAccessException: Exception occurred inside setter of com.simpleprogrammer.User.proteinData
    at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:88)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:710)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:371)
    at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4509)
    at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:186)
    at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:137)
    at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1108)
    at org.hibernate.loader.Loader.processResultSet(Loader.java:964)
    at org.hibernate.loader.Loader.doQuery(Loader.java:911)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:312)
    at org.hibernate.loader.Loader.loadEntity(Loader.java:2121)
    at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)
    at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)
    at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3927)
    at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:460)
    at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:429)
    at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:206)
    at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:145)
    at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1092)
    at org.hibernate.internal.SessionImpl.immediateLoad(SessionImpl.java:1007)
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:173)
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:285)
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
    at com.simpleprogrammer.User_$$_javassist_0.getName(User_$$_javassist_0.java)
    at com.pluralsight.Introduction_To_Hibernate_Pluralsight.Program.main(Program.java:45)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:65)
    ... 25 more
Caused by: java.lang.NullPointerException
    at com.simpleprogrammer.User.setProteinData(User.java:44)
    ... 30 more
</code></pre>

<p>The error comes from <code>setProteinData()</code> method in the <code>User</code> class. The last statement in the error displays <code>java.lang.NullPointerException</code> and points to that method. I don't know what I am doing wrong.</p>