openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jerry Carter <je...@jerrycarter.org>
Subject Help on basic @Strategy
Date Mon, 08 Mar 2010 17:41:51 GMT
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.MyPoint@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.


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message