-->
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: MappingException Unknown Entity
PostPosted: Tue Sep 19, 2006 12:54 pm 
Newbie

Joined: Fri Sep 15, 2006 4:40 pm
Posts: 4
I have mapped my table correctly in the hbm.xml file. In addition, I also included the resource file (User.hbm.xml) in the hibernate config file. My config file is similar to the one below:

hibernate.cfg.xml


Code:
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.datasource">java:comp/...</property>
    <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
    <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
    <property name="hibernate.cache.use_query_cache">true</property>
    <property name="hibernate.show_sql">false</property>
    <property name="hibernate.jdbc.use_get_generated_keys">true</property>
    <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
   
    <mapping resource="testSHJ/User.hbm.xml"/>

  </session-factory>
</hibernate-configuration>



User.hbm.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class name="testSHJ.User" table="user">
    <id name="id" column="id">
      <generator class="native"></generator>
    </id>
    <property name="profile_id" column="profile_id"/>
    <property name="realm" column="realm"/>
    <property name="username" column="username"/>
    <property name="password" column="password"/>
    <property name="created" column="created"/>
    <property name="modified" column="modified"/>
    <property name="lastlog" column="lastlog"/>
    <property name="failed" column="failed"/>
  </class>
</hibernate-mapping>


I am using the latest version of hibernate and Spring 1.28. However, when I query the class, I get the following error:

Code:
org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: from testSHJ.User u where u.realm = ?; nested exception is org.hibernate.MappingException: Unknown entity: from testSHJ.User u where u.realm = ?
org.hibernate.MappingException: Unknown entity: from testSHJ.User u where u.realm = ?


My query is: getHibernateTemplate().get("from User u where u.realm = ?",realm)


Top
 Profile  
 
 Post subject: Unknown entity
PostPosted: Tue Sep 19, 2006 4:39 pm 
Newbie

Joined: Fri Sep 15, 2006 4:40 pm
Posts: 4
My bad! I should use find() instead of get() because get() expect an object not a query. That is, getHibernateTemplate().get(User.class,userID). The correct format is:

Code:
List list = getHibernateTemplate().find("from User u where u.realm = ?",realm);
return (User)list.get(0);


Top
 Profile  
 
 Post subject: Re: Unknown entity
PostPosted: Tue Sep 19, 2006 8:50 pm 
Newbie

Joined: Tue Aug 29, 2006 2:54 am
Posts: 16
tnguyen1012 wrote:
My bad! I should use find() instead of get() because get() expect an object not a query. That is, getHibernateTemplate().get(User.class,userID). The correct format is:

Code:
List list = getHibernateTemplate().find("from User u where u.realm = ?",realm);
return (User)list.get(0);


when you use getHibernateTemplate().get(User.class,userID) , you must use full qualified name for first parameter.


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.