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