-->
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: Loading object with related collections
PostPosted: Mon Feb 14, 2005 9:00 am 
Newbie

Joined: Wed Jan 05, 2005 5:30 am
Posts: 14
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]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 9:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Um. And, what can we do to help you??

You don't show:

* what happens ... exception? empty collection?? null???
* the code you are using to try and retrieve the collection
* a Hibernate log
* the persistent classes


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.