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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -