title: Hibernate unidirectional mapping on two fields
body: <p>I have a Creature class and Item Class:</p>
  
  <p>I need unidirectional mapping in Creature as follows:</p>
  
  <pre><code>@Entity
  public  class Creature {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long id;
  
      @OneToMany(cascade = CascadeType.ALL)
      private List&lt;Item&gt; equippedItems;
  
      @OneToMany(cascade = CascadeType.ALL)
      private List&lt;Item&gt; itemsInBackpack;
  
      //getters/setters
  }
  </code></pre>
  
  <p>Hibernate creates additional table:</p>
  
  <p>| Creature_id | itemsInBackpack_id | equippedItems_id |</p>
  
  <p>This is fine for me. But the problem is that both itemsInBackpack_id and equippedItems_id have nullable set to false. This causes the following exception:</p>
  
  <pre><code>Caused by: java.sql.SQLException: Field 'itemsInBackpack_id' doesn't have a default value
  </code></pre>
  
  <p>How to tell Hibernate to allow null values on those columns?</p>
  
  <p>Edit:</p>
  
  <p>this is how I save it:</p>
  
  <pre><code>Item item1 = new Item();
  Item item2 = new Item();
  
  creature.getEquippedItems().add(item1);
  creature.getItemsInBackpack().add(item2);
  
  repository.save(creature);
  </code></pre>
  
  <p>Edit</p>
  
  <p>Item class:</p>
  
  <pre><code>@Entity
  public class Item {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long id;
  
      public long getId() {
          return id;
      }
  
  }
  </code></pre>
  
  <p>What I want to achieve: Item can be only in backpack or equipped. Not Both.</p>