You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by farsad <fa...@hotmail.com> on 2007/11/09 19:06:44 UTC

org.springframework.dao.InvalidDataAccessApiUsageException: Encountered unmanaged object

I have never encountered this problem under the current circumstances. My
question is if you can have two different <entity>s (or tables in the
database) inherit from the same MappedSuperClass?

I have defined two entities whose corresponding classes both inherit from
the same class.
ie. Entity A and Entity B are both inheriting from class C.

<mappedsuperclass C>

<entityA>
<entityB>

When ever I am writing to A, there is no problem.. when ever I am trying to
write to B, I get the exception in the subject line.

Can anyone help?
Thanks
-- 
View this message in context: http://www.nabble.com/org.springframework.dao.InvalidDataAccessApiUsageException%3A-Encountered-unmanaged-object-tf4779217.html#a13672144
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: org.springframework.dao.InvalidDataAccessApiUsageException: Encountered unmanaged object

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Farsad,

Can you post the complete annotations and xml that you are using to  
define the relationships?

Thanks,

Craig

On Nov 9, 2007, at 10:06 AM, farsad wrote:

>
> I have never encountered this problem under the current  
> circumstances. My
> question is if you can have two different <entity>s (or tables in the
> database) inherit from the same MappedSuperClass?
>
> I have defined two entities whose corresponding classes both  
> inherit from
> the same class.
> ie. Entity A and Entity B are both inheriting from class C.
>
> <mappedsuperclass C>
>
> <entityA>
> <entityB>
>
> When ever I am writing to A, there is no problem.. when ever I am  
> trying to
> write to B, I get the exception in the subject line.
>
> Can anyone help?
> Thanks
> -- 
> View this message in context: http://www.nabble.com/ 
> org.springframework.dao.InvalidDataAccessApiUsageException%3A- 
> Encountered-unmanaged-object-tf4779217.html#a13672144
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: org.springframework.dao.InvalidDataAccessApiUsageException: Encountered unmanaged object

Posted by farsad <fa...@hotmail.com>.
Hi,

I am doing a persist(header) first followed by a persist(item).

What I don't understand is that I am doing the same thing when I persist
Item 1 (ErrorItemVO). I get the error when I try persisting Item 2
(InErrorVO). 

These two items share the same Mapped Super Class. 





klaasjan elzinga wrote:
> 
> Did you try putting the Cascade persist and cascade merge on the
> item->header relation? I think the exception means that the item is
> being persisted and encounters a not persisted (managed) header. Or
> try by calling persist(header) and after that the persist(item).
> 
> KlaasJan
> 
> On Nov 9, 2007 8:06 PM, farsad <fa...@hotmail.com> wrote:
>>
>> Yes, Thanks for responding. The ErrorItemVO is written to the DB with no
>> problems. InErrorVO gives me the problem.
>>
>>
>> Here is the mapped super class's annotation:
>> @XmlAccessorType(XmlAccessType.NONE)
>> @XmlType(name = "ErrorItem", propOrder = {
>>     "error",
>>     "header",
>>     "captureDate",
>>     "isn",
>>     "micr",
>>     "region",
>>     "currency",
>>     "businessDate",
>>     "owning",
>>     "offset"
>> })
>> public class ErrorItem {
>>
>>     @XmlElement(name = "Error", required = true)
>>     protected ErrorFile error;
>>     @XmlElement(name = "Header", type = HeaderVO.class)
>>     protected HeaderVO header;
>>     @XmlElement(name = "CaptureDate", type = String.class)
>>     @XmlJavaTypeAdapter(Adapter2 .class)
>>     @XmlSchemaType(name = "date")
>>     protected Date captureDate;
>>     @XmlElement(name = "ISN")
>>     protected String isn;
>>     @XmlElement(name = "MICR")
>>     protected MICR micr;
>>     @XmlElement(name = "Region")
>>     protected String region;
>>     @XmlElement(name = "Currency")
>>     protected Currency currency;
>>     @XmlElement(name = "BusinessDate", type = String.class)
>>     @XmlJavaTypeAdapter(Adapter2 .class)
>>     @XmlSchemaType(name = "date")
>>     protected Date businessDate;
>>     @XmlElement(name = "Owning")
>>     protected Owning owning;
>>     @XmlElement(name = "Offset")
>>     protected Offset offset;
>>
>> Here are the two entities
>>
>> public class ErrorItemVO extends ErrorItem implements Serializable {
>>
>>         private static final long serialVersionUID = 1L;
>>         private long id;
>>
>>         public long getId() {
>>                 return id;
>>         }
>>
>>         public void setId(long id) {
>>                 this.id = id;
>>         }
>>
>> }
>>
>> and
>>
>> public class InErrorVO extends ErrorItem implements Serializable {
>>
>>         private static final long serialVersionUID = 1L;
>>
>>         private long id;
>>
>>         public long getId() {
>>                 return id;
>>         }
>>
>>         public void setId(long id) {
>>                 this.id = id;
>>         }
>>
>> }
>>
>> and here is the xml mappings
>>
>>     <mapped-superclass class="com.symcor.sis.sisinternal.ErrorItem" >
>>         <attributes>
>>                         <basic name="captureDate">
>>                         <column name="PROCESSING_DATE" />
>>                         <temporal>DATE</temporal>
>>                 </basic>
>>                         <basic name="isn">
>>                         <column name="ISN" length="12" />
>>                 </basic>
>>                         <basic name="region">
>>                         <column name="REGION_CODE" />
>>                 </basic>
>>                         <basic name="businessDate">
>>                         <column name="BUSINESS_DATE" />
>>                         <temporal>DATE</temporal>
>>                 </basic>
>>                         <basic name="currency" fetch="EAGER">
>>                                 <column name="CURRENCY_TYPE" length="3"
>> />
>>                                 <enumerated>STRING</enumerated>
>>                         </basic>
>>                 <many-to-one name="header">
>>                                 <join-column name="HEADER_RECORD_ID" />
>>                         </many-to-one>
>>                 <embedded name="micr"/>
>>                 <embedded name="error"/>
>>                 <embedded name="owning"/>
>>                 <embedded name="offset"/>
>>         </attributes>
>>     </mapped-superclass>
>>
>>     <entity class="com.symcor.sis.eps.vo.HeaderVO">
>>         <table name="HEADER_RECORD">
>>                 <unique-constraint>
>>                 <column-name>SOURCE_APPLICATION_CODE</column-name>
>>                 <column-name>FCN</column-name>
>>                 <column-name>CLIENT_CODE</column-name>
>>                 </unique-constraint>
>>         </table>
>>         <attributes>
>>                 <id name="id">
>>                         <column name="HEADER_RECORD_ID" nullable="false"
>> />
>>                         <generated-value strategy="SEQUENCE"
>> generator="HeaderRecordSeq"/>
>>                                 <sequence-generator
>> name="HeaderRecordSeq"
>> sequence-name="SEQ_HEADER_RECORD_ID" initial-value="0" />
>>                         </id>
>>         </attributes>
>>     </entity>
>>     <entity class="com.symcor.sis.eps.vo.ErrorItemVO">
>>         <table name="ERROR_RECORD" />
>>                 <attributes>
>>                         <id name="id">
>>                                 <column name="ERROR_RECORD_ID"
>> nullable="false" />
>>                         <generated-value strategy="SEQUENCE"
>> generator="ErrorRecordSeq"/>
>>                         <sequence-generator name="ErrorRecordSeq"
>> sequence-name="SEQ_ERROR_RECORD_ID" initial-value="0"/>
>>                         </id>
>>                 </attributes>
>>     </entity>
>>     <entity class="com.symcor.sis.eps.vo.InErrorVO">
>>         <table name="IN_ERROR_RECORD" />
>>                 <attributes>
>>                         <id name="id">
>>                                 <column name="IN_ERROR_RECORD_ID"
>> nullable="false" />
>>                         <generated-value strategy="SEQUENCE"
>> generator="InErrorRecordSeq"/>
>>                         <sequence-generator name="InErrorRecordSeq"
>> sequence-name="SEQ_IN_ERROR_RECORD_ID" initial-value="0"/>
>>                         </id>
>>                 </attributes>
>>     </entity>
>>
>> The full error says:
>> Caused by: org.springframework.dao.InvalidDataAccessApiUsageException:
>> Encountered unmanaged object "com.symcor.sis.eps.vo.HeaderVO@1f1298d" in
>> persistent field "com.symcor.sis.sisinternal.ErrorItem.header" of managed
>> object "com.symcor.sis.eps.vo.ErrorItemVO@726e15" during flush.  However,
>> this fie
>> ld does not allow cascade persist.  You cannot flush unmanaged objects.;
>> nested exception is <4|false|0.9.6-incubating>
>> org.apache.openjpa.persistence
>> .InvalidStateException: Encountered unmanaged object
>> "com.symcor.sis.eps.vo.HeaderVO@1f1298d" in persistent field
>> "com.symcor.sis.sisinternal.ErrorItem.header" of managed object
>> "com.symcor.sis.eps.vo.ErrorItemVO@726e15" during flush.  However, this
>> field does not allow cascade persist.  You cannot
>> flush unmanaged objects.
>>
>>
>>
>>
>>
>> farsad wrote:
>> >
>> > I have never encountered this problem under the current circumstances.
>> My
>> > question is if you can have two different <entity>s (or tables in the
>> > database) inherit from the same MappedSuperClass?
>> >
>> > I have defined two entities whose corresponding classes both inherit
>> from
>> > the same class.
>> > ie. Entity A and Entity B are both inheriting from class C.
>> >
>> > <mappedsuperclass C>
>> >
>> > <entityA>
>> > <entityB>
>> >
>> > When ever I am writing to A, there is no problem.. when ever I am
>> trying
>> > to write to B, I get the exception in the subject line.
>> >
>> > Can anyone help?
>> > Thanks
>> >
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/org.springframework.dao.InvalidDataAccessApiUsageException%3A-Encountered-unmanaged-object-tf4779217.html#a13673209
>>
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/org.springframework.dao.InvalidDataAccessApiUsageException%3A-Encountered-unmanaged-object-tf4779217.html#a13726946
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: org.springframework.dao.InvalidDataAccessApiUsageException: Encountered unmanaged object

Posted by klaasjan elzinga <kl...@gmail.com>.
Did you try putting the Cascade persist and cascade merge on the
item->header relation? I think the exception means that the item is
being persisted and encounters a not persisted (managed) header. Or
try by calling persist(header) and after that the persist(item).

KlaasJan

On Nov 9, 2007 8:06 PM, farsad <fa...@hotmail.com> wrote:
>
> Yes, Thanks for responding. The ErrorItemVO is written to the DB with no
> problems. InErrorVO gives me the problem.
>
>
> Here is the mapped super class's annotation:
> @XmlAccessorType(XmlAccessType.NONE)
> @XmlType(name = "ErrorItem", propOrder = {
>     "error",
>     "header",
>     "captureDate",
>     "isn",
>     "micr",
>     "region",
>     "currency",
>     "businessDate",
>     "owning",
>     "offset"
> })
> public class ErrorItem {
>
>     @XmlElement(name = "Error", required = true)
>     protected ErrorFile error;
>     @XmlElement(name = "Header", type = HeaderVO.class)
>     protected HeaderVO header;
>     @XmlElement(name = "CaptureDate", type = String.class)
>     @XmlJavaTypeAdapter(Adapter2 .class)
>     @XmlSchemaType(name = "date")
>     protected Date captureDate;
>     @XmlElement(name = "ISN")
>     protected String isn;
>     @XmlElement(name = "MICR")
>     protected MICR micr;
>     @XmlElement(name = "Region")
>     protected String region;
>     @XmlElement(name = "Currency")
>     protected Currency currency;
>     @XmlElement(name = "BusinessDate", type = String.class)
>     @XmlJavaTypeAdapter(Adapter2 .class)
>     @XmlSchemaType(name = "date")
>     protected Date businessDate;
>     @XmlElement(name = "Owning")
>     protected Owning owning;
>     @XmlElement(name = "Offset")
>     protected Offset offset;
>
> Here are the two entities
>
> public class ErrorItemVO extends ErrorItem implements Serializable {
>
>         private static final long serialVersionUID = 1L;
>         private long id;
>
>         public long getId() {
>                 return id;
>         }
>
>         public void setId(long id) {
>                 this.id = id;
>         }
>
> }
>
> and
>
> public class InErrorVO extends ErrorItem implements Serializable {
>
>         private static final long serialVersionUID = 1L;
>
>         private long id;
>
>         public long getId() {
>                 return id;
>         }
>
>         public void setId(long id) {
>                 this.id = id;
>         }
>
> }
>
> and here is the xml mappings
>
>     <mapped-superclass class="com.symcor.sis.sisinternal.ErrorItem" >
>         <attributes>
>                         <basic name="captureDate">
>                         <column name="PROCESSING_DATE" />
>                         <temporal>DATE</temporal>
>                 </basic>
>                         <basic name="isn">
>                         <column name="ISN" length="12" />
>                 </basic>
>                         <basic name="region">
>                         <column name="REGION_CODE" />
>                 </basic>
>                         <basic name="businessDate">
>                         <column name="BUSINESS_DATE" />
>                         <temporal>DATE</temporal>
>                 </basic>
>                         <basic name="currency" fetch="EAGER">
>                                 <column name="CURRENCY_TYPE" length="3" />
>                                 <enumerated>STRING</enumerated>
>                         </basic>
>                 <many-to-one name="header">
>                                 <join-column name="HEADER_RECORD_ID" />
>                         </many-to-one>
>                 <embedded name="micr"/>
>                 <embedded name="error"/>
>                 <embedded name="owning"/>
>                 <embedded name="offset"/>
>         </attributes>
>     </mapped-superclass>
>
>     <entity class="com.symcor.sis.eps.vo.HeaderVO">
>         <table name="HEADER_RECORD">
>                 <unique-constraint>
>                 <column-name>SOURCE_APPLICATION_CODE</column-name>
>                 <column-name>FCN</column-name>
>                 <column-name>CLIENT_CODE</column-name>
>                 </unique-constraint>
>         </table>
>         <attributes>
>                 <id name="id">
>                         <column name="HEADER_RECORD_ID" nullable="false" />
>                         <generated-value strategy="SEQUENCE" generator="HeaderRecordSeq"/>
>                                 <sequence-generator name="HeaderRecordSeq"
> sequence-name="SEQ_HEADER_RECORD_ID" initial-value="0" />
>                         </id>
>         </attributes>
>     </entity>
>     <entity class="com.symcor.sis.eps.vo.ErrorItemVO">
>         <table name="ERROR_RECORD" />
>                 <attributes>
>                         <id name="id">
>                                 <column name="ERROR_RECORD_ID" nullable="false" />
>                         <generated-value strategy="SEQUENCE" generator="ErrorRecordSeq"/>
>                         <sequence-generator name="ErrorRecordSeq"
> sequence-name="SEQ_ERROR_RECORD_ID" initial-value="0"/>
>                         </id>
>                 </attributes>
>     </entity>
>     <entity class="com.symcor.sis.eps.vo.InErrorVO">
>         <table name="IN_ERROR_RECORD" />
>                 <attributes>
>                         <id name="id">
>                                 <column name="IN_ERROR_RECORD_ID" nullable="false" />
>                         <generated-value strategy="SEQUENCE" generator="InErrorRecordSeq"/>
>                         <sequence-generator name="InErrorRecordSeq"
> sequence-name="SEQ_IN_ERROR_RECORD_ID" initial-value="0"/>
>                         </id>
>                 </attributes>
>     </entity>
>
> The full error says:
> Caused by: org.springframework.dao.InvalidDataAccessApiUsageException:
> Encountered unmanaged object "com.symcor.sis.eps.vo.HeaderVO@1f1298d" in
> persistent field "com.symcor.sis.sisinternal.ErrorItem.header" of managed
> object "com.symcor.sis.eps.vo.ErrorItemVO@726e15" during flush.  However,
> this fie
> ld does not allow cascade persist.  You cannot flush unmanaged objects.;
> nested exception is <4|false|0.9.6-incubating>
> org.apache.openjpa.persistence
> .InvalidStateException: Encountered unmanaged object
> "com.symcor.sis.eps.vo.HeaderVO@1f1298d" in persistent field
> "com.symcor.sis.sisinternal.ErrorItem.header" of managed object
> "com.symcor.sis.eps.vo.ErrorItemVO@726e15" during flush.  However, this
> field does not allow cascade persist.  You cannot
> flush unmanaged objects.
>
>
>
>
>
> farsad wrote:
> >
> > I have never encountered this problem under the current circumstances. My
> > question is if you can have two different <entity>s (or tables in the
> > database) inherit from the same MappedSuperClass?
> >
> > I have defined two entities whose corresponding classes both inherit from
> > the same class.
> > ie. Entity A and Entity B are both inheriting from class C.
> >
> > <mappedsuperclass C>
> >
> > <entityA>
> > <entityB>
> >
> > When ever I am writing to A, there is no problem.. when ever I am trying
> > to write to B, I get the exception in the subject line.
> >
> > Can anyone help?
> > Thanks
> >
>
>
>
> --
> View this message in context: http://www.nabble.com/org.springframework.dao.InvalidDataAccessApiUsageException%3A-Encountered-unmanaged-object-tf4779217.html#a13673209
>
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Re: org.springframework.dao.InvalidDataAccessApiUsageException: Encountered unmanaged object

Posted by farsad <fa...@hotmail.com>.
Yes, Thanks for responding. The ErrorItemVO is written to the DB with no
problems. InErrorVO gives me the problem. 


Here is the mapped super class's annotation:
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(name = "ErrorItem", propOrder = {
    "error",
    "header",
    "captureDate",
    "isn",
    "micr",
    "region",
    "currency",
    "businessDate",
    "owning",
    "offset"
})
public class ErrorItem {

    @XmlElement(name = "Error", required = true)
    protected ErrorFile error;
    @XmlElement(name = "Header", type = HeaderVO.class)
    protected HeaderVO header;
    @XmlElement(name = "CaptureDate", type = String.class)
    @XmlJavaTypeAdapter(Adapter2 .class)
    @XmlSchemaType(name = "date")
    protected Date captureDate;
    @XmlElement(name = "ISN")
    protected String isn;
    @XmlElement(name = "MICR")
    protected MICR micr;
    @XmlElement(name = "Region")
    protected String region;
    @XmlElement(name = "Currency")
    protected Currency currency;
    @XmlElement(name = "BusinessDate", type = String.class)
    @XmlJavaTypeAdapter(Adapter2 .class)
    @XmlSchemaType(name = "date")
    protected Date businessDate;
    @XmlElement(name = "Owning")
    protected Owning owning;
    @XmlElement(name = "Offset")
    protected Offset offset;

Here are the two entities

public class ErrorItemVO extends ErrorItem implements Serializable {
	
	private static final long serialVersionUID = 1L;
	private long id;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
	
}

and

public class InErrorVO extends ErrorItem implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private long id;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
	
}

and here is the xml mappings

    <mapped-superclass class="com.symcor.sis.sisinternal.ErrorItem" >
    	<attributes>
			<basic name="captureDate">
         		<column name="PROCESSING_DATE" />
         		<temporal>DATE</temporal>
         	</basic>
			<basic name="isn">
         		<column name="ISN" length="12" />
         	</basic>
			<basic name="region">
         		<column name="REGION_CODE" />
         	</basic>
			<basic name="businessDate">
         		<column name="BUSINESS_DATE" />
         		<temporal>DATE</temporal>
         	</basic>
			<basic name="currency" fetch="EAGER">
				<column name="CURRENCY_TYPE" length="3" />
				<enumerated>STRING</enumerated>
			</basic>
         	<many-to-one name="header">
				<join-column name="HEADER_RECORD_ID" />
			</many-to-one>
         	<embedded name="micr"/>
         	<embedded name="error"/>
         	<embedded name="owning"/>
         	<embedded name="offset"/>
    	</attributes>
    </mapped-superclass>

    <entity class="com.symcor.sis.eps.vo.HeaderVO">
    	<table name="HEADER_RECORD">
    		<unique-constraint>
            	<column-name>SOURCE_APPLICATION_CODE</column-name>
            	<column-name>FCN</column-name>
            	<column-name>CLIENT_CODE</column-name>
        	</unique-constraint>
    	</table>
    	<attributes>
    		<id name="id">
    			<column name="HEADER_RECORD_ID" nullable="false" />
    			<generated-value strategy="SEQUENCE" generator="HeaderRecordSeq"/>	                 
				<sequence-generator name="HeaderRecordSeq"
sequence-name="SEQ_HEADER_RECORD_ID" initial-value="0" />  
			</id>
    	</attributes>
    </entity>            
    <entity class="com.symcor.sis.eps.vo.ErrorItemVO">
    	<table name="ERROR_RECORD" />
		<attributes>
			<id name="id">
				<column name="ERROR_RECORD_ID" nullable="false" />
	    		<generated-value strategy="SEQUENCE" generator="ErrorRecordSeq"/>
	    		<sequence-generator name="ErrorRecordSeq"
sequence-name="SEQ_ERROR_RECORD_ID" initial-value="0"/> 
			</id>
		</attributes>
    </entity>
    <entity class="com.symcor.sis.eps.vo.InErrorVO">
    	<table name="IN_ERROR_RECORD" />
		<attributes>
			<id name="id">
				<column name="IN_ERROR_RECORD_ID" nullable="false" />
	    		<generated-value strategy="SEQUENCE" generator="InErrorRecordSeq"/>
	    		<sequence-generator name="InErrorRecordSeq"
sequence-name="SEQ_IN_ERROR_RECORD_ID" initial-value="0"/>  
			</id>
		</attributes>
    </entity>

The full error says:
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException:
Encountered unmanaged object "com.symcor.sis.eps.vo.HeaderVO@1f1298d" in
persistent field "com.symcor.sis.sisinternal.ErrorItem.header" of managed
object "com.symcor.sis.eps.vo.ErrorItemVO@726e15" during flush.  However,
this fie
ld does not allow cascade persist.  You cannot flush unmanaged objects.;
nested exception is <4|false|0.9.6-incubating>
org.apache.openjpa.persistence
.InvalidStateException: Encountered unmanaged object
"com.symcor.sis.eps.vo.HeaderVO@1f1298d" in persistent field
"com.symcor.sis.sisinternal.ErrorItem.header" of managed object
"com.symcor.sis.eps.vo.ErrorItemVO@726e15" during flush.  However, this
field does not allow cascade persist.  You cannot
flush unmanaged objects.




farsad wrote:
> 
> I have never encountered this problem under the current circumstances. My
> question is if you can have two different <entity>s (or tables in the
> database) inherit from the same MappedSuperClass?
> 
> I have defined two entities whose corresponding classes both inherit from
> the same class.
> ie. Entity A and Entity B are both inheriting from class C.
> 
> <mappedsuperclass C>
> 
> <entityA>
> <entityB>
> 
> When ever I am writing to A, there is no problem.. when ever I am trying
> to write to B, I get the exception in the subject line.
> 
> Can anyone help?
> Thanks
> 



-- 
View this message in context: http://www.nabble.com/org.springframework.dao.InvalidDataAccessApiUsageException%3A-Encountered-unmanaged-object-tf4779217.html#a13673209
Sent from the OpenJPA Users mailing list archive at Nabble.com.