title: Dropwizard Hibernate 1.0.0
body: <p>I'm having an issue with a bi-directional mapping between a one-to-many relationship whereby the many is not getting it's foreign key updated - it remains null when performing an update/create. There are two entities, the first (many) is this:</p>
  
  <pre><code>@Entity
  @Table(name = "availability")
  public class Availability implements Serializable {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  protected Long id;
  
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "PERSON_ID", nullable = false)
  private Person person;
  </code></pre>
  
  <p>The second is the one:</p>
  
  <pre><code>@Entity
  @Table(name = "PERSON")
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  @DiscriminatorColumn(name = "discriminator", discriminatorType = DiscriminatorType.STRING)
  @DiscriminatorValue(value = "P")
  public abstract class Person implements Serializable {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  protected Long id;
  
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "person")
  private Collection&lt;Availability&gt; availabilities;
  </code></pre>
  
  <p>There are a couple of things that might be causing this, but I'm uncertain of what the real reason is. The first is that Person is abstract. However the inheritence type I'm using should not be causing this issue.</p>
  
  <p>The second is the way in which I'm trying to persist the entity in a single transaction. I'm using dropwizard's @UnitOfWork. My DAO is doing the following:</p>
  
  <pre><code>public Staff update(Staff staff) {
      return persist(staff);
  }
  </code></pre>
  
  <p>Staff at this point does not have an id. Availability is set on Person (also without an id)</p>
  
  <p>Under the hood, this is simply calling the following:</p>
  
  <pre><code>protected E persist(E entity) throws HibernateException {
      currentSession().saveOrUpdate(requireNonNull(entity));
      return entity;
  }
  </code></pre>
  
  <p>Should i be using the session manager to open a new transaction, persist person, get the id back, set that on availability and then perform an update with person with the modified availability? It seems to me that would just be wrong.</p>