java - Hibernate: Saving null entity in many-to-one relationship -
there similar question, case bit different cascading defined.
on trying save task non-empty siteentity - works fine. however, when try save 1 null siteentity there null parameter exception (unsuprisingly) - , using dummy siteentity ends in creating new row in sites table...
this relevant piece of code (irrelevant data omitted):
@javax.persistence.table(name = "tasks") @entity public class task { @id @generatedvalue @column(name = "id", unique = true, nullable = false) private int id; @manytoone(cascade = cascadetype.all, fetch=fetchtype.eager) @joincolumn(name="siteid", nullable = true) @notfound(action = notfoundaction.ignore) @foreignkey(name = "id") private siteentity site; } @javax.persistence.table(name = "sites") @entity public class siteentity { @id @column(name = "id") @generatedvalue(strategy=generationtype.auto) private int id; }
question is, basically, how can save task null siteentity - result 0 written tasks table's siteid column?
p.s. removing cascade entirely (to save "as , deal site later") didn't change situation.
thank help!
going ondrej bozek's idea - issue "not null" constraint on siteid. removing solved issue.
Comments
Post a Comment