-->
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.  [ 4 posts ] 
Author Message
 Post subject: MappingException: Unknown Entity: java.lang.String?
PostPosted: Fri Jul 20, 2007 4:25 pm 
Newbie

Joined: Fri Jul 20, 2007 4:05 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
Latest - Hibernate 3.2.4.SP1

Mapping documents:

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="com.mirapoint.doccenter.User" table="USERS">
      <id name="id" column="USER_ID">
         <generator class="native"/>
      </id>
      <property name="username" type="string" column="USERNAME"/>
      <property name="password" type="string" column="PASSWORD"/>
   </class>
</hibernate-mapping>


hibernate.cfg.xml:

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:/tmp/doccenter.hsql</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>
      <!-- Mapping Files -->
        <mapping resource="com/mirapoint/doccenter/User.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


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

Code:
      Session dbSession = sessionFactory.getCurrentSession();
      dbSession.beginTransaction();
      Query q = dbSession.createQuery("from User where username = ?");
      q.setEntity(0, username);
      List<User> l = q.list();
      User thisUser = null;
      if (l.size() == 1) thisUser = (User) q.uniqueResult();
      dbSession.getTransaction().commit();
      dbSession.close();


Full stack trace of any exception that occurs:

Code:
14:19:13,519 ERROR [[LoginServlet]] Servlet.service() for servlet LoginServlet threw exception
org.hibernate.MappingException: Unknown entity: java.lang.String
   at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
   at org.hibernate.impl.SessionFactoryImpl.getIdentifierType(SessionFactoryImpl.java:637)
   at org.hibernate.type.EntityType.getIdentifierType(EntityType.java:487)
   at org.hibernate.type.EntityType.getIdentifierOrUniqueKeyType(EntityType.java:512)
   at org.hibernate.type.ManyToOneType.getColumnSpan(ManyToOneType.java:65)
   at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:305)
   at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:275)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:75)
   at com.mirapoint.doccenter.LoginServlet.service(LoginServlet.java:99)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
   at java.lang.Thread.run(Thread.java:613)


Note that this line is line 99 of LoginServlet.java

Code:
      List<User> l = q.list();


Name and version of the database you are using:

HSql 1.8.0

The generated SQL (show_sql=true):

(From the doccenter.hsql.log file)

adrian-halls-computer:/tmp adrianhall$ more doccenter.hsql.log
/*C2*/SET SCHEMA PUBLIC
CONNECT USER SA
SET AUTOCOMMIT FALSE
SET AUTOCOMMIT TRUE
drop table USERS if exists
create table USERS (USER_ID bigint generated by default as identity (start with
1), USERNAME varchar(255), PASSWORD varchar(255), primary key (USER_ID))
SET AUTOCOMMIT FALSE


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 4:58 pm 
Regular
Regular

Joined: Mon Apr 19, 2004 6:54 pm
Posts: 79
try with
Code:
q.setString(0, username);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 5:05 pm 
Newbie

Joined: Fri Jul 20, 2007 4:05 pm
Posts: 2
Thanks - that was a "duh" problem, I guess.

It wasn't the only problem with the code, but the answer I absolutely needed to get past the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 6:09 pm 
Newbie

Joined: Mon Feb 16, 2009 2:27 pm
Posts: 7
Nice,i was looking for this answer.

setString for strings......why didn't anyone tell me this

setEntity is not for strings

Thanks


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