• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

saving entity with a lazy property

 
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 ?
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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
 
machines help you to do more, but experience less. Experience this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic