When deleting the @Embeddable object, I run into some problems.
I have the following domain classes: SwitchVoipTrunkGroup and PrioritizedCodec. The latter contains several fields that may be null.
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<PrioritizedCodec> prioritizedCodecs = new HashSet<PrioritizedCodec>();
}
@Embeddable
public class PrioritizedCodec {
@Column(name = "PRIORITY")
private String priority;
@Column(name = "FAX_MODE")
private String faxMode;
}
When I edit the PrioritizedCodecs SwitchVoipTrunkGroup field (for example, deleting an entry) and saving the object, I see the following in the Hibernate log:
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=?
From this question, I understand why Hibernate uses all the fields in the where clause. However, this gives problems: if some of these fields are empty, the query will look like this:
delete from T_SWITCH_VOIP_TKG_CODEC where fk_switch_voip_tkg_id=1 and fax_mode = ''
and priority =''
However, this will not delete any entries, since it is really necessary for Hibernate to check NULL iso for an empty string. For instance:
delete from T_SWITCH_VOIP_TKG_CODEC where fk_switch_voip_tkg_id=1 and fax_mode
IS NULL and priority IS NULL
(. , )
, ? !