-->
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: Unknown entity class: java.lang.Integer
PostPosted: Wed Dec 22, 2004 5:38 pm 
Beginner
Beginner

Joined: Fri Jan 16, 2004 4:58 pm
Posts: 37
I am trying to work on some simple mappings to try and begin once again to understand how hibernate works (I'm tired of writing a ton of SQL ).

I have 3 beans that have related tables. Employee, User, and Issue. The issue table in the database has 2 foreign keys. 1 for user_id and one for employee_id. I am trying to query for an issue with a specific createdByUser (user_id). And for some reason I am getting the Unknown entity class: java.lang.Integer error messsage. Below are all the relivant files. Thanks for any help.

Hibernate Version: 2.1.7c

Issue.java
Code:
public class Issue
{
    private int issueId;
    private String issueNumber;
    private User createdByUser;
    private Employee employee;

    public int getIssueId()
    {
        return issueId;
    }

    public void setIssueId(int issueId)
    {
        this.issueId = issueId;
    }

    public String getIssueNumber()
    {
        return issueNumber;
    }

    public void setIssueNumber(String issueNumber)
    {
        this.issueNumber = issueNumber;
    }

    public User getCreatedByUser()
    {
        return createdByUser;
    }

    public void setCreatedByUser(User createdByUser)
    {
        this.createdByUser = createdByUser;
    }

    public Employee getEmployee()
    {
        return employee;
    }

    public void setEmployee(Employee employee)
    {
        this.employee = employee;
    }
}


User.java
Code:
public class User implements Serializable
{
    private Integer userId;
    private String username;
    private String password;
    private String firstName;
    private String lastName;
    private String emailAddress;
    private int role;

    public User() { }

    public Integer getUserId()
    {
        return userId;
    }

    public void setUserId(Integer userId)
    {
        this.userId = userId;
    }

    public String getUsername()
    {
        return username;
    }

    public void setUsername(String username)
    {
        this.username = username;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }

    public String getEmailAddress()
    {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress)
    {
        this.emailAddress = emailAddress;
    }

    public int getRole()
    {
        return role;
    }

    public void setRole(int role)
    {
        this.role = role;
    }
}


Employee.java
Code:
public class Employee
{
    private int employeeId;
    private String firstName;
    private String lastName;
    private String department;
    private String phone;
    private String mailStop;
    private String email;

    public int getEmployeeId()
    {
        return employeeId;
    }

    public void setEmployeeId(int employeeId)
    {
        this.employeeId = employeeId;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }

    public String getDepartment()
    {
        return department;
    }

    public void setDepartment(String department)
    {
        this.department = department;
    }

    public String getPhone()
    {
        return phone;
    }

    public void setPhone(String phone)
    {
        this.phone = phone;
    }

    public String getMailStop()
    {
        return mailStop;
    }

    public void setMailStop(String mailStop)
    {
        this.mailStop = mailStop;
    }

    public String getEmail()
    {
        return email;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }
}


Mapping documents:

Employee.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

    <class name="com.intrust.anykey.beans.Employee" table="t_employee">
        <id name="employeeId" column="employee_id" type="int">
            <generator class="assigned"/>
        </id>

        <property name="firstName" column="first_name" type="string"/>
        <property name="lastName" column="last_name" type="string"/>
        <property name="department" column="department" type="string"/>
        <property name="phone" column="phone" type="string" />
        <property name="mailStop" column="mail_stop" type="string" />
        <property name="email" column="email" type="int"/>

    </class>
</hibernate-mapping>


User.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="com.intrust.anykey.beans.User" table="t_user">
        <id name="userId" column="user_id" type="int">
            <generator class="assigned"/>
        </id>

        <property name="username" column="username" type="string"/>
        <property name="password" column="password" type="string"/>
        <property name="firstName" column="first_name" type="string"/>
        <property name="lastName" column="last_name" type="string" />
        <property name="emailAddress" column="email" type="string" />
        <property name="role" column="role_id" type="int"/>

    </class>
</hibernate-mapping>


Issue.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

    <class name="com.intrust.anykey.beans.Issue" table="t_issue">
        <id name="issueId" column="issue_id" type="int">
            <generator class="identity"/>
        </id>

        <property name="issueNumber" column="issue_number" type="string"/>

        <many-to-one
            name="createdByUser"
            column="creating_user_id"
            class="com.intrust.anykey.beans.User"/>

        <many-to-one
            name="employee"
            column="employee_id"
            class="com.intrust.anykey.beans.Employee"/>

    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
Criterion userEq = Expression.eq("createdByUser", new Integer(9715));
Criteria crt = session.createCriteria(Issue.class);
crt.add(userEq);
Issue issue = (Issue)crt.uniqueResult();


Full stack trace of any exception that occurs:

Code:
net.sf.hibernate.MappingException: Unknown entity class: java.lang.Integer
   at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:347)
   at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2710)
   at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2717)
   at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2779)
   at net.sf.hibernate.type.EntityType.getIdentifier(EntityType.java:66)
   at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:47)
   at net.sf.hibernate.loader.Loader.bindPositionalParameters(Loader.java:749)
   at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:788)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
   at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
   at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:118)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3648)
   at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
   at net.sf.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:385)
   at com.intrust.anykey.test.hibernate.HibernateTest.main(HibernateTest.java:33)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)

_________________
Gregg Bolinger
Javaranch Sheriff
Weblog


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 6:10 pm 
Beginner
Beginner

Joined: Fri Jan 16, 2004 4:58 pm
Posts: 37
I solved this problem by changing this line of code:

Code:
Criterion userEq = Expression.eq("createdByUser.userId", new Integer(9715));

_________________
Gregg Bolinger
Javaranch Sheriff
Weblog


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.