Hey all
I am trying to load an object and it collections Unfortunatly the collections arent there, even though I know they are saved.
The object is an object called Person, and a person have a Set of projects. I cannot retrive the Projects.
Thanks
- Middy
My loading code
Code:
public static Person getPerson(String handle,String password) throws NoSuchElementException, HibernateException{
//gets session for thread if not created,create one
Session s = HibernateUtil.currentSession();
Query query = s.createQuery("from data.Person as pers where pers.handle='"+handle+"' and " + " pers.password ='"+password+"'");
Iterator i = query.iterate();
return (Person)i.next();
}
mapping documents
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<!-- Created Fri Jan 07 11:24:24 PST 2005 -->
<hibernate-mapping package="data">
<class name="Person" table="person">
<id name="personId" column="Person_ID" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="handle" column="Handle" type="java.lang.String" not-null="true" />
<property name="password" column="Password" type="java.lang.String" not-null="true" />
<property name="createddate" column="CreatedDate" type="java.lang.Long" not-null="true" />
<property name="name" column="FullName" type="java.lang.String" not-null="true" />
<set name="projects" table="person_owns_project" inverse="true" cascade ="all">
<key column="FK_Person_ID"/>
<many-to-many column="FK_Project_ID" class ="data.Project"/>
</set>
<joined-subclass name="Employee" table="employee">
<key column="Employee_ID"/>
</joined-subclass>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<!-- Created Fri Jan 07 11:26:54 PST 2005 -->
<hibernate-mapping package="data">
<class name="Project" table="project">
<id name="projectId" column="Project_ID" type="java.lang.Integer" unsaved-value="0" >
<generator class="native"/>
</id>
<property name="projectName" column="Project_name" type="java.lang.String" not-null="true" />
<property name="projectStartDate" column="Project_start_date" type="java.lang.Long" not-null="true" />
<set name="customers" table="person_owns_project" cascade="all" >
<key column="FK_Project_ID"/>
<many-to-many column="FK_Person_ID" class ="data.Person"/>
</set>
<set name="employees" table="employee_workson_project" cascade="all">
<key column="FK_Project_ID"/>
<many-to-many column="FK_Employee_ID" class ="data.Employee"/>
</set>
<list name="folders" table="Folder" cascade="all">
<key column="FK_Project_ID"/>
<index column="list_idx" />
<one-to-many class="data.Folder"/>
</list>
</class>
</hibernate-mapping>
[/code]