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.