java - Lazy loading problem with one to one mapping -


i have 2 simple pojos , have 1 one mapping between them.

  1. contact.java
  2. comment.java -- has foreign key column contact.java

the code have written below.

contact.java

@onetoone(optional= false,cascade = cascadetype.all, mappedby="contact", fetch=fetchtype.lazy) @org.hibernate.annotations.lazytoone(org.hibernate.annotations.lazytooneoption.no_proxy) private comment mcomment; 

comment.java

@onetoone(fetch = fetchtype.lazy,cascade=cascadetype.all ) @joincolumn(name="ew_cntc_id") private contact contact; 

i setting comment contact pojo , saving contact.java

if keep @onetoone(optional= false, getting dataintegrityexception, constraintvoilationexception

if changed @onetoone(optional= true, working.

i think if optional false, trying insert contact, find comment trying insert comment, has reference contact has set foreign key without inserting contact cannot keep foreign key .. if optional true contact can inserted without comment , pk generated contact , tat set in foreign key column of contact.--- anyway issue solved.

one more thing loading contacts need lazy load comments, no working can 1 on this, strictly need lazy loading of comment because of performance problm.

thanks in advance.

we have issue in hibernate 3. hibernate 4 fixed issue.

if want load contacts not comments try this(imply change manytoone relation).

@manytoone(fetch=fetchtype.lazy) private comment mcomment; 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -