java - Spring-Data JPA: modelling a graph getting 'column violates not-null' when removing edges -


i have set of entities that build sort of graph. modelled class entity 2 fields modelling relationships between entities.

@onetomany(cascade = cascadetype.all, orphanremoval = true) @joincolumn(name = "fromid") private set<entityrelation> outedges;  @onetomany(cascade = cascadetype.all) @joincolumn(name = "toid") private set<entityrelation> inedges; 

all outedges supposed belong entity when saved, inedges "inferred" these. problem after removing out-edge error error: null value in column "fromid" violates not-null constraint fromid field of entityrelation.

for performance reasons, don't want have direct relations form entity entity.

to fix this, used new spring-data jpa method (in corresponding repository class) explicitly remove entity points (like

@modifying @query(value = "delete entityrelation fromid = ?1", nativequery = true) int deleteentityrelations(string entityid); 

but somehow misses whole point, since want jpa take responsibility of that.

what wrong here? got stuck, since posts find suggest should work orphan-delete.

in sql-trace can see org.hibernate.sql - update entityrelation set fromid=null fromid=? , id=? issued automatically (which triggers error).

thanks , regards fricke

this known issue of hibernate. in scenarios (and found 1 of them) violates constraints on foreign key relations. there various options (but i'm afraid might not of them)

  • remove constraint. know, know ..

  • make constraint deferred. not sure if feature available in other databases oracle.

  • limit expectations jpa. seriously, looks expecting more give you. highly recommend reading article before proceeding project using kind of orm.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -