I've a mapping one-to-many but hibernate don't try to remove...instead delete, hibernate tries to do an update and set null to keys..it throws me an exception:

Hibernate: update participation\_released set idt\_released=null where idt\_released=?

How can i fix it? I want to remove all collection if list is empty!

Actually my mapping is like:

Owner.java

```
@OneToMany(cascade = {CascadeType.ALL})
@JoinColumn(name = "idt_released")
public List<ParticipationReleased> getParticipationReleases() {
    return participationReleases;
}

```

Son.java

```
@Entity
@Table(name = "participation_released")
public class ParticipationReleased implements Serializable {

private static final long serialVersionUID = 1L;

private ParticipationReleasedPK participationReleasedPK;
private Released released;
private Colaborator colaborator;
private PerformanceType performanceType;

public ParticipationReleased() {
    this(null, null, null);
}

public ParticipationReleased(Released released, Colaborator colaborator,
        PerformanceType performanceType) {
    super();
    this.released = released;
    this.colaborator = colaborator;
    this.performanceType = performanceType;
}

public ParticipationReleased(ParticipationReleasedPK participationReleasedPK) {
    super();
    this.participationReleasedPK = participationReleasedPK;
}

@EmbeddedId
public ParticipationReleasedPK getParticipationReleasedPK() {
    return participationReleasedPK;
}

public void setParticipationReleasedPK(
        ParticipationReleasedPK participationReleasedPK) {
    this.participationReleasedPK = participationReleasedPK;
}

@Transient
public Released getReleased() {
    return released;
}

public void setReleased(Released released) {
    this.released = released;
}

@ManyToOne(cascade = { CascadeType.REFRESH })
@JoinColumn(name = "idt_colaborator", insertable = false, updatable = false)
public Colaborator getColaborator() {
    return colaborator;
}

public void setColaborator(Colaborator colaborator) {
    this.colaborator = colaborator;
}

@ManyToOne(cascade = { CascadeType.REFRESH })
@JoinColumn(name = "idt_performance_type", insertable = false, updatable = false)
public PerformanceType getPerformanceType() {
    return performanceType;
}

public void setPerformanceType(PerformanceType performanceType) {
    this.performanceType = performanceType;
}
}

```

SonEmbeddableId.java

```
@Embeddable
public class ParticipationReleasedPK implements Serializable {

private static final long serialVersionUID = 1L;

private Integer idtReleased;
private Integer idtColaborator;
private Integer idtPerformanceType;

public ParticipationReleasedPK() {
}

public ParticipationReleasedPK(Integer idtReleased, Integer idtColaborator,
        Integer idtPerformanceType) {
    super();
    this.idtReleased = idtReleased;
    this.idtColaborator = idtColaborator;
    this.idtPerformanceType = idtPerformanceType;
}

@Column(name = "idt_released", nullable = false)
public Integer getIdtReleased() {
    return idtReleased;
}

public void setIdtReleased(Integer idtReleased) {
    this.idtReleased = idtReleased;
}

@Column(name = "idt_colaborator", nullable = false)
public Integer getIdtColaborator() {
    return idtColaborator;
}

public void setIdtColaborator(Integer idtColaborator) {
    this.idtColaborator = idtColaborator;
}

@Column(name = "idt_performance_type", columnDefinition = "smallint", nullable = false)
public Integer getIdtPerformanceType() {
    return idtPerformanceType;
}

public void setIdtPerformanceType(Integer idtPerformanceType) {
    this.idtPerformanceType = idtPerformanceType;
}
}

```

Exception:

```
 Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:1052)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:170)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:996)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1141)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:88)
... 119 more
Caused by: java.sql.BatchUpdateException: Column 'idt_released' cannot be null
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 133 more

```