This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

saving entity with a lazy property  RSS feed

 
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: 9643
42
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
 
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
 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!