0

I am attempting to remove an entity and delete its row from the database using the following method:

public void remove(Object o){
        this.persistence.entityManager().remove(o);
    }

When I attempt to do so I am getting the error:

ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-01407: cannot update ("SCHEMA"."TABLE"."COLUMN") to NULL

I know that there is a IS NOT NULL CONSTRAINT on this column.

But why would this matter if the row is going to be deleted? I do not understand why I am getting this error?

java123999
  • 6,974
  • 36
  • 77
  • 121
  • Are you sure it's the entity you are removing, and not a parent/child relationship? Perhaps an orphan? – Boris the Spider Aug 19 '16 at 15:00
  • because (i'm guessing here) the error comes from a foreign key constraint, ie the key pointing to the row you are trying to delete cannot be set to null – guido Aug 19 '16 at 15:00
  • @BoristheSpider I am removing any child relationships first? – java123999 Aug 19 '16 at 15:02
  • @ᴳᵁᴵᴰᴼ please explain further? – java123999 Aug 19 '16 at 15:02
  • @java123999 why are you asking me? I didn't write your code. I don't know what cascades you have on the DB or in JPA itself. – Boris the Spider Aug 19 '16 at 15:03
  • Ok, is it not possible to carry out this deletion without removing the constraint? – java123999 Aug 19 '16 at 15:20
  • 1
    Of course it is. You just need to respect the constraints that you yourself have imposed. If you have required that `parent_id` on a child is `NOT NULL` and you delete the `Parent`, then Hibernate will update the `parent_id` to `NULL` - called "orphaning". This will cause the delete to fail; and with good reason. You need to understand what it is that you are deleting and the impact that has; as well as what cascade means - both at the JPA level and at the SQL level. – Boris the Spider Aug 19 '16 at 15:34

0 Answers0