openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jerry Carter (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (OPENJPA-1569) @Strategy triggers an InvalidStateException for fields which are declared as Java interfaces
Date Sat, 13 Mar 2010 05:19:27 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-1569?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12844808#action_12844808
] 

Jerry Carter edited comment on OPENJPA-1569 at 3/13/10 5:18 AM:
----------------------------------------------------------------

Chased this down into the code for a bit.  In SingleFieldManager.preFlush(FieldMetaData, int,
int, int, boolean, boolean, OpCallbacks), interfaces have a type of JavaTypes.PC_UNTYPED whereas
classes are JavaTypes.OBJECT.  The decision logic for setting this value appears to come from
org.apache.openjpa.meta.JavaTypes::getTypeCode(Class<?> type):

        if (type.isInterface()) {
            if (type == Serializable.class)
                return OBJECT;
            return PC_UNTYPED;
        }

Here the interface (BaseAddress) enters the outer 'if' and returns PC_UNTYPED whereas the
actual class (USAddress) skips this section.

      was (Author: no1uno):
    Chased this down into the code for a bit.  In SingleFieldManager.preFlush(FieldMetaData,
int, int, int, boolean, boolean, OpCallbacks), interfaces have a type of JavaTypes.PC_UNTYPED
whereas classes are JavaTypes.OBJECT.  The decision logic for setting this value is not readily
apparent to the uninitiated.
  
> @Strategy triggers an InvalidStateException for fields which are declared as Java interfaces
> --------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1569
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1569
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-beta2
>         Environment: MacOS X, Spring 3.0, Maven
>            Reporter: Jerry Carter
>
> The @Strategy annotation works fine for classes but does not work if the field is a Java
interface.  Consider:
> 	@Persistent
> 	@Strategy("SimpleHandler")
> 	@Column(name="address_packed")
> 	private BaseAddress address;
> 	public BaseAddress getAddress() { return address; }
> 	public void setAddress(BaseAddress address) { this.address = address; }
> This works perfectly if BaseAddress is defined as a class but results in an InvalidStateException
if it is an interface:
> <openjpa-2.0.0-beta2-rexported fatal user error> org.apache.openjpa.persistence.InvalidStateException:
Encountered unmanaged object in persistent field "com.example.SimpleEntity.address" 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.USAddress@4e0a39de
> 	at org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:767)
> 	at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:614)
> 	at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:575)
> 	at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:491)
> 	at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2956)
> 	at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40)
> 	at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1048)
> 	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2051)
> 	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2011)
> 	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1782)
> 	at org.apache.openjpa.kernel.DelegatingBroker.flush(DelegatingBroker.java:1015)
> 	at org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:637)
> 	... etc ...
> Here com.example.USAddress is a class which implements the BaseAddress interface.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message