• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

saving entity with a lazy property

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Your buns are mine! But you can have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic