How to insert in to multiple tables via Hibernate
<p>I have two tables I need to insert in to in Hibernate - I have a User and every user belongs is a Member. Therfore when creating a new user I need a new entry in the Member table. I have attempted this via creating a Member object which maps to my member table and then having that as a field in my User object which maps to the user table </p>

<pre><code>@Entity
@Table(name = "USER")
public class User
{
    @Id
    @GeneratedValue
    @Column(name = "id")
    private int id;

    @Column(name = "username")
    private String username;

    @Column(name = "password")
    private String password;

    @Column(name = "fullName")
    private String fullName;

    //other fields ommited

    @OneToOne
    @JoinColumn(name = "id")
    private Member member;
</code></pre>

<p>My member pojo looks as follows</p>

<pre><code>@Entity
@Table(name = "MEMBER")
public class Member
{
    @Id
    @GeneratedValue
    @Column(name = "id")
    private int id;

    @Column(name = "sgpid")
    private int sgpid;

    @Column(name = "username")
    private String username;
</code></pre>

<p>Trying to save the object i do as follows;</p>

<pre><code>@Override
public boolean addUser(User user)
{
    if (user == null)
    {
        throw new IllegalArgumentException("Unable to add null user");
    }

    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();
    session.save(user);
    session.getTransaction().commit();

    return true;
}
</code></pre>

<p>This gives me the row saved in my user table but the entry is not inserted in to the member table. I think my linking annotations are probably incorrect but I am not too sure - please could someone provide some assistance.</p>

<p>Thanks</p>