Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0
Mapping documents:<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<sql-query name="depts">
<return alias="dept"
class="com.test.hibernate.DeptDTO"/>
SELECT d.dept_id AS {d.dept_id}, d.dept_name AS {d.dept_name} FROM dept d
</sql-query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Query query = session.getNamedQuery("depts");
List deptDTO = query.list();
Full stack trace of any exception that occurs: SEVERE: Error in named query: depts
org.hibernate.MappingException: Unknown entity: com.test.hibernate.DeptDTO
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:548)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.getSQLLoadable(SQLQueryReturnProcessor.java:312)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processRootReturn(SQLQueryReturnProcessor.java:353)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:332)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:148)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:64)
at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:444)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:351)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)
at com.test.hibernate.util.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:31)
at com.test.hibernate.java.NamedQuery.main(NamedQuery.java:33)
Initial SessionFactory creation failed.org.hibernate.HibernateException: Errors in named queries: depts
Exception in thread "main" java.lang.NullPointerException
at com.test.hibernate.java.NamedQuery.main(NamedQuery.java:46)
Name and version of the database you are using:MySQL 5.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
The DTO that has been set in .hbm.xml package com.test.hibernate;
/**
* @author I097630
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DeptDTO {
private int dept_id;
private String dept_name;
/**
* @return Returns the dept_id.
*/
public int getDept_id() {
return dept_id;
}
/**
* @param dept_id The dept_id to set.
*/
public void setDept_id(int dept_id) {
this.dept_id = dept_id;
}
/**
* @return Returns the dept_name.
*/
public String getDept_name() {
return dept_name;
}
/**
* @param dept_name The dept_name to set.
*/
public void setDept_name(String dept_name) {
this.dept_name = dept_name;
}
}