aspose file tools*
The moose likes Object Relational Mapping and the fly likes saving entity with a lazy property  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "saving entity with a lazy property  " Watch "saving entity with a lazy property  " New topic
Author

saving entity with a lazy property

srini carry
Ranch Hand

Joined: Nov 30, 2007
Posts: 83
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

Joined: Aug 03, 2008
Posts: 9293
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
srini carry
Ranch Hand

Joined: Nov 30, 2007
Posts: 83
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
srini carry
Ranch Hand

Joined: Nov 30, 2007
Posts: 83
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
 
Consider Paul's rocket mass heater.
 
subject: saving entity with a lazy property