title: How to delete Hibernate @Embeddables containing nullable fields?
body: <p>When deleting an @Embeddable object, I run into some problems.</p>
  
  <p>I have the following domain classes: SwitchVoipTrunkGroup and PrioritizedCodec. The latter contains several fields that are nullable.</p>
  
  <pre><code>class SwitchVoipTrunkGroup {
  
      //...
  
      @CollectionOfElements(fetch = FetchType.LAZY)
      @JoinTable(
              name = "SWITCH_VOIP_TKG_CODEC",
              joinColumns = @JoinColumn(name = "FK_SWITCH_VOIP_TKG_ID")
      )
      @ForeignKey(name = "FK_CODEC_SWITCH_VOIP_TKG")
      private Set&lt;PrioritizedCodec&gt; prioritizedCodecs = new HashSet&lt;PrioritizedCodec&gt;();
  
      //...
  }
  
  @Embeddable
  public class PrioritizedCodec {
  
      @Column(name = "PRIORITY")
      private String priority;
  
      @Column(name = "FAX_MODE")
      private String faxMode;
  
      //... some more columns ...
  }
  </code></pre>
  
  <p>When I edit SwitchVoipTrunkGroup's prioritizedCodecs field (e.g. by deleting an entry) and save the entity, I see the following in my Hibernate logging:</p>
  
  <pre><code>13:54:31,919 INFO  [STDOUT] Hibernate: delete from T_SWITCH_VOIP_TKG_CODEC where 
  fk_switch_voip_tkg_id=? and fax_mode=? and priority=?
  </code></pre>
  
  <p>From <a href="https://stackoverflow.com/questions/3742897/hibernate-elementcollection-strange-delete-insert-behavior">this question</a> I understand why Hibernate uses all the fields in the where clause. However, this gives problems: in case some of these fields are empty, the query will look like so:</p>
  
  <pre><code>delete from T_SWITCH_VOIP_TKG_CODEC where fk_switch_voip_tkg_id=1 and fax_mode = '' 
  and priority =''
  </code></pre>
  
  <p>This will however not delete any records, as what is really necessary is for Hibernate to check for NULL iso for an empty string. For example:</p>
  
  <pre><code>delete from T_SWITCH_VOIP_TKG_CODEC where fk_switch_voip_tkg_id=1 and fax_mode
  IS NULL and priority IS NULL
  </code></pre>
  
  <p>(cf. <a href="http://www.techonthenet.com/oracle/questions/empty_null.php" rel="nofollow noreferrer">here</a> for more info on why checking for an empty string does not suffice)</p>
  
  <p>Any ideas on how to tackle this? Many thx!</p>