mysql - Database and Hibernate one-to-one best appraoch -


which general , better approach implement one-to-one relation , mapping db , hibernate bellow assume have customer & contact tables. 1) can keep contact_id in customer table foreign key 2) can keep customer_id in contact table foreign key how implement hibernate mapping both?

i have implemented customer , contact tables using 2nd option when i'm tryiing hibernatetemplate.save(customer);

i'm getting bellow exception: cannot add or update child row: foreign key constraint fails (contact_info, constraint contact_info_ibfk_1 foreign key (customer_id) references customers (id))

present mapping is

@entity customerentity {     .....     @onetoone(cascade = cascadetype.all, fetch = fetchtype.eager)     @joincolumn(name="customer_id")     private contactinfoentity contactdetails;     ..... } @entity contactinfoentity {      @column(name="customer_id")     private int customerid; } 

@onetoone difficult , confusing implement. can use @manytoone , set property unique=true. mentioned in hibernate documentation @manytoone can used on @onetoone clean way.

some 1 posted similar question here:

hibernate - why use many-to-one represent one-to-one?


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -