Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

saving entity with a lazy property

 
srini carry
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an entity with a property bytes which is lazy , this holds byte array and property isfinal a boolean .

I display these entities in a web page with a radio button , indicating final , when user selects a radio button I retrieve the selected radio button and retrieve the entity corresponding to the radio button and update it with isfinal to true and call saveOrUpdate , hibernate saves the entity running an update statement for all properties and because the property bytes is lazy and I did not call getBytes() the value is null and null is saved to column bytes in database , so any time I save this entity without loading bytes property bytes property becomes null , please help me how to handle this ?
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you try to retrieve a lazily loaded entity from an unmanaged entity, then you should get an exception not null. Can you show us the mapped entity files and any mapping files...
 
srini carry
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:If you try to retrieve a lazily loaded entity from an unmanaged entity, then you should get an exception not null. Can you show us the mapped entity files and any mapping files...


I am not talking about loading a lazy property.More over the entity is in managed state.My problem is when I call saveorupdate hibernate is tryibng to persists lazy property , becasue I did not load this property the value is null and null gets persisted
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little confused, is it a property or an association you have here?

If it is a property you are persisting, albiet a lazy one. So if it is null and you call saveOrUpdate it will behave exactly like any other null property on a mapped object. Either load the lazy property or, if this is not desirable, use the dynamic-update and dynamic-insert elements in your class mapping.
 
srini carry
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:I'm a little confused, is it a property or an association you have here?

If it is a property you are persisting, albiet a lazy one. So if it is null and you call saveOrUpdate it will behave exactly like any other null property on a mapped object. Either load the lazy property or, if this is not desirable, use the dynamic-update and dynamic-insert elements in your class mapping.


please tell me how can I use dynamic-update and dynamic-insert for annotated classes , I know in xml but not in annotation please tell me
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic