Re: Replacing Entities while Managed

2006-11-08 Thread Abe White
The merge operation takes as a parameter a detached instance, not a  
new instance.


TopLink Essentials might not be able to tell the difference between  
a detached and a new instance. So it might work in that environment.


But the behavior you're describing is not portable.



That said, you can probably fool OpenJPA into attaching a new  
instance if you want to.  The documentation describes the general  
heuristics OpenJPA uses to determine whether an instance is detached:


http://incubator.apache.org/openjpa/docs/latest/manual/ 
manual.html#ref_guide_attach_behavior




___
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.


Re: Replacing Entities while Managed

2006-11-08 Thread Abe White
The merge operation takes as a parameter a detached instance, not a  
new instance.


TopLink Essentials might not be able to tell the difference between  
a detached and a new instance. So it might work in that environment.


But the behavior you're describing is not portable.


That said, you can probably fool OpenJPA into attaching a new  
instance if you want to.  The documentation describes the general  
heuristics OpenJPA uses to determine whether an instance is detached:


http://incubator.apache.org/openjpa/docs/latest/manual/ 
manual.html#ref_guide_attach_behavior

___
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.


Re: Replacing Entities while Managed

2006-11-07 Thread Craig L Russell

Hi Don,

The merge operation takes as a parameter a detached instance, not a  
new instance.


TopLink Essentials might not be able to tell the difference between a  
detached and a new instance. So it might work in that environment.


But the behavior you're describing is not portable.

Is there a way to detach an instance with the identity you want to  
merge, and update that instance? Then you would have a portable  
application.


Craig

On Nov 7, 2006, at 4:55 PM, DonBrady wrote:



Surely.


(1) We do a find method which returns an entity A from the database.

(2) We also have an unmanaged entity instance B separately, that we  
created
outside any persistence context, whose values we wish to use to  
update those

in A, and then rewrite A to the database.

(3) We just set the key of B to that of A (namely "48") and do a  
"merge."

This worked to update A in TopLink Essentials.

(4) Under OpenJPA, we get the exact error message:


An object of type "com.xxx.entity.entities.FeCmeCommittee" with oid
"48"
already exists in this context; another cannot be persisted.



(5) This seems wrong.  The reason the two objects have the same id is
precisely that we want to update the existing entity.


THANK YOU.

Don



Craig L Russell wrote:


Hi Don,

Could you please be just a bit more specific about what you are
trying to do and what error you encounter?

Thanks,

Craig

On Nov 7, 2006, at 2:50 PM, DonBrady wrote:



We are converting a TopLink Essentials application to OpenJPA

Under Toplink Essentials, we could replace a managed entity with
another
that had the same identity (key) by doing a merge.

When we try this in OpenJPA, we get the following error:

An object of type "com.xxx.entity.entities.FeCmeCommittee" with oid
"48"
already exists in this context; another cannot be persisted.

However, "48" is actually the identity or key, not the oid.  The
oid's are
different. They key is the same and therefore it should be
possible to
replace it via a merge.

Or am I missing something?

Thanks,

Don


--
View this message in context: http://www.nabble.com/Replacing-
Entities-while-Managed-tf2592059.html#a7229110
Sent from the open-jpa-dev mailing list archive at Nabble.com.



Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/ 
jdo

408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!






--
View this message in context: http://www.nabble.com/Replacing- 
Entities-while-Managed-tf2592059.html#a7230848

Sent from the open-jpa-dev mailing list archive at Nabble.com.



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



smime.p7s
Description: S/MIME cryptographic signature


Re: Replacing Entities while Managed

2006-11-07 Thread DonBrady

Surely.


(1) We do a find method which returns an entity A from the database.

(2) We also have an unmanaged entity instance B separately, that we created
outside any persistence context, whose values we wish to use to update those
in A, and then rewrite A to the database.

(3) We just set the key of B to that of A (namely "48") and do a "merge." 
This worked to update A in TopLink Essentials.

(4) Under OpenJPA, we get the exact error message:

> An object of type "com.xxx.entity.entities.FeCmeCommittee" with oid  
> "48"
> already exists in this context; another cannot be persisted.
>

(5) This seems wrong.  The reason the two objects have the same id is
precisely that we want to update the existing entity.


THANK YOU.

Don



Craig L Russell wrote:
> 
> Hi Don,
> 
> Could you please be just a bit more specific about what you are  
> trying to do and what error you encounter?
> 
> Thanks,
> 
> Craig
> 
> On Nov 7, 2006, at 2:50 PM, DonBrady wrote:
> 
>>
>> We are converting a TopLink Essentials application to OpenJPA
>>
>> Under Toplink Essentials, we could replace a managed entity with  
>> another
>> that had the same identity (key) by doing a merge.
>>
>> When we try this in OpenJPA, we get the following error:
>>
>> An object of type "com.xxx.entity.entities.FeCmeCommittee" with oid  
>> "48"
>> already exists in this context; another cannot be persisted.
>>
>> However, "48" is actually the identity or key, not the oid.  The  
>> oid's are
>> different.     They key is the same and therefore it should be  
>> possible to
>> replace it via a merge.
>>
>> Or am I missing something?
>>
>> Thanks,
>>
>> Don
>>
>>
>> -- 
>> View this message in context: http://www.nabble.com/Replacing- 
>> Entities-while-Managed-tf2592059.html#a7229110
>> Sent from the open-jpa-dev mailing list archive at Nabble.com.
>>
> 
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:[EMAIL PROTECTED]
> P.S. A good JDO? O, Gasp!
> 
> 
>  
> 

-- 
View this message in context: 
http://www.nabble.com/Replacing-Entities-while-Managed-tf2592059.html#a7230848
Sent from the open-jpa-dev mailing list archive at Nabble.com.



Re: Replacing Entities while Managed

2006-11-07 Thread Craig L Russell

Hi Don,

Could you please be just a bit more specific about what you are  
trying to do and what error you encounter?


Thanks,

Craig

On Nov 7, 2006, at 2:50 PM, DonBrady wrote:



We are converting a TopLink Essentials application to OpenJPA

Under Toplink Essentials, we could replace a managed entity with  
another

that had the same identity (key) by doing a merge.

When we try this in OpenJPA, we get the following error:

An object of type "com.xxx.entity.entities.FeCmeCommittee" with oid  
"48"

already exists in this context; another cannot be persisted.

However, "48" is actually the identity or key, not the oid.  The  
oid's are
different. They key is the same and therefore it should be  
possible to

replace it via a merge.

Or am I missing something?

Thanks,

Don


--
View this message in context: http://www.nabble.com/Replacing- 
Entities-while-Managed-tf2592059.html#a7229110

Sent from the open-jpa-dev mailing list archive at Nabble.com.



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



smime.p7s
Description: S/MIME cryptographic signature


Replacing Entities while Managed

2006-11-07 Thread DonBrady

We are converting a TopLink Essentials application to OpenJPA

Under Toplink Essentials, we could replace a managed entity with another
that had the same identity (key) by doing a merge.

When we try this in OpenJPA, we get the following error:

An object of type "com.xxx.entity.entities.FeCmeCommittee" with oid "48"
already exists in this context; another cannot be persisted.

However, "48" is actually the identity or key, not the oid.  The oid's are
different. They key is the same and therefore it should be possible to
replace it via a merge.

Or am I missing something?

Thanks,

Don


-- 
View this message in context: 
http://www.nabble.com/Replacing-Entities-while-Managed-tf2592059.html#a7229110
Sent from the open-jpa-dev mailing list archive at Nabble.com.