persistence@glassfish.java.net

Re: delay in ManyToOne relationship updates

From: josu <josu.eh.mondo_at_gmail.com>
Date: Fri, 25 Sep 2009 05:53:11 -0700 (PDT)

I really thought JPA was responsible for maintaining the relationship, so
making both asignments would be problematic. But the solution you both gave
me is working ok. Thanks for making things clear.



christopher delahunt wrote:
>
> Hello,
>
> JPA does not maintain relationships for you, so the best way to ensure
> that the child is in the parent's list is to add it. When you set the
> child's parent, also add the child to the parent's list of children.
>
> Otherwise, you must flush the database and then refresh the parent for
> the database, causing unnecessary database hits. This is why you also
> see the child in the parent's children on restart, since it causes
> the parent to be brought in from the database - essentially the same as
> a refresh.
>
> Best Regards,
> Chris
>
> josu wrote:
>> Hello.
>>
>> I am developping an application using Toplink 2.0.1 persistence and
>> Glassfish 2.1.
>>
>> I have an entity with a OneToMany/ManyToOne relationship to itself (an
>> article can have a single father-article, and a father can have several
>> item-articles), defined like this:
>>
>> @Entity
>> public class Article implements java.io.Serializable,
>> java.lang.Comparable{
>>
>> ...
>>
>> private Article father;
>> private List<Article> items;
>>
>> ...
>>
>> @ManyToOne
>> public Article getFather(){
>> return father;
>> }
>>
>> public void setFather(Article father){
>> this.father=father;
>> }
>>
>> @OneToMany(mappedBy="father")
>> public List<Article> getItems(){
>> return items;
>> }
>>
>> public void setItems(List<Article> items){
>> this.items=items;
>> }
>> }
>>
>> There are more properties in the entity but i don't mention them as they
>> aren't relevant.
>>
>> The issue is that when I set an article's father, father's item list is
>> not
>> updated inmediatly. In fact, I don't get it updated until I restart
>> Glassfish.
>>
>> How could I force that update be made inmediatly?
>>
>> Thanks.
>>
>
>

-- 
View this message in context: http://www.nabble.com/delay-in-ManyToOne-relationship-updates-tp25567844p25611657.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.