You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Himadri <hi...@yahoo.co.in> on 2010/03/04 14:02:17 UTC

How to update Many-to-one relationship ?

Hi,

I have requirement to update Many-to-one relationship ,

For instance , Books belong to one author >> Book (*- 1) Author1

I need to update Book1 to point to another Author1. 
I have tried using em.merge(Book) with CascadeType.MERGE but it doesnt work.
It should work.

There is no exception generated , but the data is also not updated in
database. 

Can anyone explain me how to update Book1 to point to another Author.

Thanks in advance

-H



-- 
View this message in context: http://n2.nabble.com/How-to-update-Many-to-one-relationship-tp4674124p4674124.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: How to update Many-to-one relationship ?

Posted by Himadri <hi...@yahoo.co.in>.
Sorry .. my mistake ..Please ignore it . Yes its working.  Only
book.setAuthor(differentAuthor) is enough. Even merge isnt required. Book is
updated to point to differentAuthor.

Thanks
-- 
View this message in context: http://n2.nabble.com/How-to-update-Many-to-one-relationship-tp4674124p4679564.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: How to update Many-to-one relationship ?

Posted by Daryl Stultz <da...@6degrees.com>.
On Thu, Mar 4, 2010 at 8:02 AM, Himadri <hi...@yahoo.co.in> wrote:

> I need to update Book1 to point to another Author1.
> I have tried using em.merge(Book) with CascadeType.MERGE but it doesnt
> work.
> It should work.
>
> I don't believe you have to do anything special. You don't need any
CascadeType settings since you are modifying the book directly (not trying
to save properties of the Author). If you just do
book.setAuthor(differentAuthor) and merge, it should work. (I don't use the
L2 cache, so I don't bother managing the inverse relation.) If not, perhaps
it's a transaction issue or a dirty-tracking issue. I have found that if you
change a property of an entity while it is attached to em1, then you detach
it and merge it on em2, the change does not take.

-- 
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com