-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate is not handling a mapped collection
PostPosted: Fri Sep 21, 2007 3:28 pm 
Beginner
Beginner

Joined: Thu Sep 16, 2004 8:14 pm
Posts: 27
Hibernate version: 3.2.0 CR1

Name and version of the database you are using: Postgres 8.2.4

I have two persisted classes, Site and Folder. 1 Site has many Folders and 1 Folder has 1 Site.

Folder's Site accessors look like this:

@ManyToOne
public Site getSite() {
return _site;
}

public void setSite(Site site) {
_site = site;
}

Site's Folder accessors look like this:

@OneToMany (mappedBy = "site")
@OrderBy("name")
public List<Folder> getFolders() {
return _folders;
}

public void setFolders(List<Folder> folders) {
_folders = folders;
}

In the schema (created by Hibernate) the folder table has an FK of site_id. The site table does not contain anything indicating which folders point to it, and there is no mapping table. So, what I think is supposed to happen is that after calling:

folder.setSite(site);

A call right after that to:

site.getFolders();

would return a collection of the Folders which point to that Site. Instead the collection is coming back empty. Hibernate does not execute any SQL during the call to getFolders(). The site_id column of the folder table does actually get populated with the correct id of the Site it points to. In fact my service method can find the list of folders associated with a site just fine.

public List<Folder> getFoldersForSite(Site site) {
return(this.getHibernateTemplate().findByNamedParam("from Folder f where f.site = :site", "site", new Object[]{ site }));
}

So, it appears that Hibernate is not managing Site's list of Folders for me. Am I missing an annotation or just expecting Hibernate to do something for me that it does not?
I have been reading all the documentation I could find and it all leads me to believe that what I'm trying should work.

http://www.hibernate.org/hib_docs/annot ... ollections

Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 11:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you are responsible for maintaining both side fo the relationship at the object level

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.