One other detail I should have mentioned.  The values are correctly retrieved 
from the database, but the exception is thrown on INSERT before the @Strategy 
class is even invoked.

On Mar 8, 2010, at 12:42 PM, No1UNo [via OpenJPA] wrote:

> I am seeing an 'unmanaged object' exception for the objects build using 
> @Strategy, but isn't that exactly the point?  These are supposed to be 
> unmanaged with the strategy being invoked as necessary for conversion.  I 
> must be missing something obvious.  ;-) 
> 
> > Caused by: <openjpa-2.0.0-beta2-r422266:915978 fatal user error> 
> > org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged 
> > object in persistent field "com.example.SimpleEntity.custom" during flush.  
> > However, this field does not allow cascade persist. Set the cascade 
> > attribute for this field to CascadeType.PERSIST or CascadeType.ALL (JPA 
> > annotations) or "persist" or "all" (JPA orm.xml), or enable cascade-persist 
> > globally, or manually persist the related field value prior to flushing. 
> > You cannot flush unmanaged objects or graphs that have persistent 
> > associations to unmanaged objects. 
> > FailedObject: com.example.mypo...@a431693 
> > at 
> > org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:767)
> >  
> 
> My entity looks something like this: 
> 
> > @Entity 
> > public abstract class SimpleEntity { 
> > @Id 
> > private long id; 
> > public long getId() { return id; } 
> > public void setId(long id) { this.id = id; } 
> > 
> > @Strategy("MyPointHandler") 
> > private MyPoint custom; 
> > MyPoint getCustom() { return custom; } 
> > void setCustom(MyPoint custom) { this. custom = custom; } 
> > 
> > ... 
> > }
> 
> With a very simple handler class: 
> 
> > public class MyPointHandler extends AbstractValueHandler { 
> >     @Override 
> >     public Column[] map(ValueMapping vm, String name, ColumnIO io, boolean 
> > adapt) { 
> >         Column c = new Column(); 
> >         c.setIdentifier(DBIdentifier.newColumn(name)); 
> >         c.setJavaType(JavaTypes.STRING); 
> >         return new Column[]{ c }; 
> >     } 
> > 
> >     public boolean isVersionable() { 
> >         return true; 
> >     } 
> > 
> >     public Object toDataStoreValue(ValueMapping vm, Object val, JDBCStore 
> > store) { 
> >         return new MyPoint((String) val); 
> >     } 
> >     
> >     public Object toObjectValue(ValueMapping vm, Object val) { 
> >     if (val == null) return null; 
> >     return ((MyPoint) val).getValue(); 
> >     } 
> > }
> 
> I've used the PointHandler from the OpenJPA tests as a model. 
> 
> 
> 
> View message @ 
> http://n2.nabble.com/Help-on-basic-Strategy-tp4696891p4696891.html 
> To start a new topic under OpenJPA Users, email 
> [email protected] 
> To unsubscribe from OpenJPA Users, click here.
> 


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

Reply via email to