3

I'm having some problems when removing a registry with a @OneToMany relationship. The entities are quite simples, although they include composite PK and inheritance:

@MappedSuperclass
public class MyTablePk {

    @Id
    @Column(name = "id1")
    private Integer id1;

    @Id
    @Column(name = "id2")
    private Integer id2;

    public MyTablePk() {
    }

    public MyTablePk(final Integer id1, final Integer id2) {
        this.id1 = id1;
        this.id2 = id2;
    }

    // getters and setters
    ...

}

@Entity
@Table(name = "my_table")
@IdClass(value = MyTablePk.class)
public class MyTable extends MyTablePk {

    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
    @JoinColumns({ @JoinColumn(name = "id1", referencedColumnName = "id1"),
            @JoinColumn(name = "id2", referencedColumnName = "id2") })
    private List<MyTableTranslation> translations = new ArrayList<MyTableTranslation>();

    // getters and setters
    ...

}

@MappedSuperclass
public class MyTableTranslationPk {

    @Id
    @Column(name = "id1")
    private Integer id1;

    @Id
    @Column(name = "id2")
    private Integer id2;

    @Id
    @Column(name = "lang")
    private String lang;

    public MyTableTranslationPk() {
    }

    public MyTableTranslationPk(final Integer id1, final Integer id2, final String lang) {
        this.id1 = id1;
        this.id2 = id2;
        this.lang = lang;
    }

    // getters and setters
    ...

}

@Entity
@Table(name = "my_table_translation")
@IdClass(value = MyTableTranslationPk.class)
public class MyTableTranslation extends MyTableTranslationPk {

    @Column(name = "text")
    private String text;

    // getters and setters
    ...

}

When removing the MyTable registry, with all the children elements, JPA tries mysteriously to update the children:

Hibernate: update my_table_translation set ID=null where ID=?
2016-07-13 10:23:24 ERROR SqlExceptionHelper:131 - ORA-01407: could not update ("PUI"."MY_TABLE_TRANSLATION"."ID") with a NULL value

Why JPA tries to update these deleted registries?

Marc Gil Sendra
  • 819
  • 2
  • 9
  • 22

0 Answers0