openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jackson12 <>
Subject Re: merge only works with managed entity
Date Fri, 07 Dec 2007 17:50:52 GMT

Thanks Kevin for your prompt response.
Here is a simple use case we have:
within an EJB , we have the following method:

public UserProfile updateUserProfile(UserProfile userProfile) {
		return getProfileDAO().update(userProfile);

when this method is called, the input parameter has all of the values
including the key, but we got a runtime exception because it's trying to
insert userProfile into database.

org.apache.openjpa.persistence.PersistenceException: ORA-00001: unique
constraint (VPDNGDITR17.PK_SECURITY_USER_PROFILE) violated FailedObject:

After we change the code to the following, it works fine:
	public UserProfile updateUserProfile(UserProfile userProfile) {
		UserProfileDAO profileDAO = getProfileDao();
		UserProfile tmpUserProfile =
		PropertyUtils.copyProperties(tmpUserProfile, userProfile);
		return getProfileDao().update(tmpUserProfile);

Here is the update method of ProfileDAO:

public T update(T entity)

When the input parameter has nested object, even the above approach won't
work any more, because PropertyUtils.copyProperties will make the nested
object not managed anymore.

Thanks a lot

Kevin Sutter wrote:
> jackson12,
> Could you be more specific with your example?  We have various testcases
> that do this exact process of merging in non-managed entities (without
> first
> retrieving the entity from the DB).   Could you further explain your test
> scenario and what results you are getting?
> Thanks,
> Kevin
> On Dec 7, 2007 11:12 AM, jackson12 <> wrote:
>> Hi, We are trying to migrate our JBoss EJB3 application to IBM websphere
>> with
>> OpenJPA. We noticed in OpenJPA, the merge method does not work with
>> non-managed entity. You have to retrieve the entity from DB, make some
>> changes and then call merge. But with JBoss's implementation, you don't
>> have
>> to retrieve the entity from DB first. the merge method works fine for
>> non-managed entity.
>> Is there anyway for OpenJPA to work the same way as JBoss's JPA
>> implementation on this part? or is there a way in OpenJPA to make a
>> non-managed entity managed?
>> thanks in advance
>> --
>> View this message in context:
>> Sent from the OpenJPA Developers mailing list archive at

View this message in context:
Sent from the OpenJPA Developers mailing list archive at

View raw message