On Mar 8, 2010, at 4:03 PM, No1UNo [via OpenJPA] wrote:

> The 'unmanaged object' exception is being caused by an inheritance 
> relationship on the Java side.  Suppose that I have a specialized class 
> derive from a base class: 'class SpecializedPoint extends MyPoint'.  If I 
> write the entity as
> 
>> 
>> @Strategy("MyPointHandler") 
>> private SpecializedPoint custom; 
>> SpecializedPoint getCustom() { return custom; } 
>> void setCustom(SpecializedPoint custom) { this. custom = custom; } 
> 
> everything works fine.  If instead I have
> 
>> 
>> @Strategy("MyPointHandler") 
>> private MyPoint custom; 
>> MyPoint getCustom() { return custom; } 
>> void setCustom(MyPoint custom) { this. custom = custom; } 
> 
> and call 'setCustom(new SpecializedPoint())' then the exception is thrown 
> when the data should be written to the database and BEFORE ever calling the 
> class designated by @Strategy.
> 
> Is this a bug in OpenJPA 2.0.0?  Most likely the behavior is by design.  This 
> prevents scenarios where the child class requires persisting more information 
> than the base class.  Unfortunately, it doesn't help much in my case as the 
> objects are serializing binary data to the database and only a single column 
> is required for the whole family of classes.  Is there a different mechanism 
> for this scenario?

FWIW, I've employed a slightly different workaround.  I defined a simple class 
holding the base class and made corresponding changes to the setter, getter, 
and strategy class.

> @Strategy("MyPointHandler")
> private HolderClass custom;
> MyPoint GetCustom() { return custom.getPoint(); }
> void setCustom(MyPoint custom) { custom = new HolderClass(custom); }

This seems unnecessary but it works.


-- 
View this message in context: 
http://n2.nabble.com/Help-on-basic-Strategy-tp4696891p4700217.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to