-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Update a collection with fetchType = eager
PostPosted: Wed Jul 14, 2010 4:15 am 
Newbie

Joined: Wed Jul 14, 2010 3:10 am
Posts: 3
Hi,

I have two objects managed by hibernate with annotations

Code:
@Entity
@Table(name = "person")
public class Person {
..........................
   @OneToMany(fetch = FetchType.EAGER, targetEntity = Address.class, cascade = CascadeType.ALL)
   @JoinColumn(name = "idforeign_add")
   public Set<Address> getAddresses() {
      return addresses;
   }
.........................
}


@Entity
@Table(name = "address")
public class Address {
.................................
        private int idaddress; //referenced address table primary key
   private int idforeign;  //foreign key
.................................
}


I have no many-to-one in address (for person) because many table are linked with address
so I don't want to put a foreign key in address for each one.

If I load person instances, it's ok I have person instances with addresses filled owned to @OneToMany(fetch = FetchType.EAGER.

When I try to update person I have a problem,
It updates person,
It updates Address,
then it tries a second update on Address :
update address set idforeign = null where idforeign = ?

It updated address just before why do Hibernate tries this second update on address ?

I note this problem happens only if I put an HashSet for my Address collection in Person
If I load Person (with its address), addresses will be loaded in a PersistentSet
I modify an address, I update Person , it will be ok, it updates person then updates address

but if put a new address collection (an hashset) in person (with same addresses) without any modification
if I try to update person, it will try to set null on idForeign.
I think hibernate considers I delete my address it want to break the relation in setting a null on the address foreign key

Eventually, with a "normal" relation so with a one-to-many on a side and many-to-one on other side
there is no problem even with a new hashset

Could you explain me this problem ?
Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.