-->
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.  [ 3 posts ] 
Author Message
 Post subject: Help with mapping parent/child with same class.
PostPosted: Wed Jul 21, 2004 11:50 am 
Beginner
Beginner

Joined: Tue Jan 06, 2004 4:51 pm
Posts: 48
Hi,

I have entities that are departments, and departments can have parent departments. I am trying to use just one class to map this. However, when I try to do a query like:
Code:
"... where employee.department.id in (:departments)";
// departmentList is an arraylist of integers
q.setParameterList("departments", departmentList);
result = q.scroll();


I get a MappingException: no persister for java.lang.Integer

Can anyone give me a better way to map this?

The class looks like:
Code:
package com.cc.tss;

/*
*
*  Java class "PaySection.java" generated from Poseidon for UML.
*  Poseidon for UML is developed by <A HREF="http://www.gentleware.com">Gentleware</A>.
*  Generated with <A HREF="http://jakarta.apache.org/velocity/">velocity</A> template engine.
*
*/
import java.io.Serializable;
public class Department implements Serializable {
   
    ///////////////////////////////////////
    // attributes
   
   
    /**
     * Represents ...
     */
    private String name;
    private String shortName;
    private String email;
    private Integer id;
    private Department parent;
   
    /**
     * Represents ...
     *
     *
     * @return
    */
   
    public Department() {
        //parent = new Department();
    }
   
    public Department getParent() {
        return parent;
    }
   
    public void setParent(Department d) {
        parent = d;
    }
   
    public String getName() {
        return name;
    } // end getname

    public void setName(String _name) {
        name = _name;
    } // end setname
   
    public String getShortName() {
        return shortName;
    } // end getname
   
    public void setShortName(String _name) {
        shortName = _name;
    } // end setname
   
    public String getEmail() {
        return email;
    } // end getname
   
    public void setEmail(String _name) {
        email = _name;
    } // end setname
   
    public Integer getId() {
        return id;
    } // end getId
   
    public void setId(Integer i) {
        id = i;
    }
   
    public boolean needsPieceEntry(){
        return DepartmentManager.needsPieceEntry(this);
    }
}


and my mapping looks like:
Code:
<hibernate-mapping>
  <!-- table created by: CREATE TABLE KEYWORDS ( ID IDENTITY, NAME VARCHAR(25) ); -->
  <class name="com.cc.tss.Department" table="dept">
       
    <id name="id" type="integer" column="id">
        <generator class="sequence">
            <param name="sequence">dept_id_seq</param>
        </generator>
    </id>
       
    <property name="name" column="name" type="string" not-null="true"/>   
    <property name="shortName" column="short_name" type="string"/>                   
    <property name="email" column="email" type="string"/>   
    <!--
    <many-to-one
        name="parent"
        class="com.cc.tss.Department"
        column="parent_id"/>                 
        -->               
  </class>
</hibernate-mapping>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 21, 2004 11:52 am 
Beginner
Beginner

Joined: Tue Jan 06, 2004 4:51 pm
Posts: 48
umm.. except the parent part in the mapping isn't commented out normally. I just commented it out for now.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 9:51 am 
Beginner
Beginner

Joined: Tue Jan 06, 2004 4:51 pm
Posts: 48
I found the problem. It was just a mistake in the query that gets that ArrayList which returns references to Departments instead of Integers.


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