-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to add object to collection without fetching
PostPosted: Wed Dec 06, 2006 11:44 am 
Newbie

Joined: Wed Dec 06, 2006 11:33 am
Posts: 3
Hibernate version: 3.2.1GA

I have a big collection of elements.
I want to add some element to collection without fetch of all collection.

There is next code:
Code:
 
  tx.begin();
  Parent parent = em.find(Parent.class, 1); // there is in db

  Foo foo = new Foo(1, 2, 3);
  foo.setParent(parent);                   // (1)

  em.merge(foo);


it works but parent_id in db is NULL.
If i add parent.getFoos().add(foo); after (1) lazy collection of foos initializes.

Are the any ideas?

Best regards,
Vadim


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 1:28 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Use the inverse attibute in such way that the parent will be the one responsible for the db update.

- http://www.hibernate.org/hib_docs/v3/re ... entinverse


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 2:18 pm 
Newbie

Joined: Wed Dec 06, 2006 11:33 am
Posts: 3
Thanks for answer!
But how can i tell hibernate entity manager to install inverse="true"? I don't have foo.hmb.xml cose i use ejb-persistence (hibernate-entitymanger). May be there is way to set it with annotations?

I did
Code:
public class Foo {
...
@JoinColumn(insertable=false, updatable=false)
public Parent getParent() {
  return parent
}
...

but it does not work.

Best regards,
Vadim Homchik


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 2:22 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Hmmm ... for the annotations I don't know how you setup inverse.
You could read through the HA docs and try to find out. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 3:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
@OneToMany(mappedBy="...")

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 5:00 pm 
Newbie

Joined: Wed Dec 06, 2006 11:33 am
Posts: 3
emmanuel wrote:
@OneToMany(mappedBy="...")


In that case Foo will be owner of relation, and i can't execute next code:
Code:
  ...
  parent.setFoos(foos);
  parent = em.merge(parent);
  ...

Are there any way to have possibility to save all collection and in some situations to add new foo without getting all collection?

Best regards,
Vadim Homchik


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 4:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I find it inconsistent

_________________
Emmanuel


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

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.