Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.2.0
<?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 package="patni.sample">
<sql-query name="test3">
SELECT ENAME AS {emp1.name}FROM employees
<return alias="emp1" class="EmployeeVO" entity-name=""/>
</sql-query>
</hibernate-mapping>
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
System.out.println("Done2");
session =sessionFactory.openSession();
System.out.println("Done3");
session.beginTransaction();
List alist = session.getNamedQuery("test3").list();
// System.out.println("The no : of Users-->"+alist.size());
System.out.println("Done");
WARN SessionFactoryObjectFactory:98 - Could not bind factory to JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.getNameParser(InitialContext.java:429)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:306)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
at Test.main(Test.java:27)
16:27:45,045 DEBUG SessionFactoryImpl:308 - instantiated session factory
16:27:45,045 DEBUG SessionFactoryImpl:390 - Checking 0 named HQL queries
16:27:45,045 DEBUG SessionFactoryImpl:410 - Checking 1 named SQL queries
16:27:45,045 DEBUG SessionFactoryImpl:418 - Checking named SQL query: test3
16:27:45,060 DEBUG QueryPlanCache:112 - unable to locate native-sql query plan in cache; generating (SELECT ENAME AS {emp1.name}FROM employees)
16:27:45,060 DEBUG SQLCustomQuery:62 - starting processing of sql query [SELECT ENAME AS {emp1.name}FROM employees]
16:27:45,107 ERROR SessionFactoryImpl:362 - Error in named query: test3
org.hibernate.MappingException: Unknown entity:
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:1291)
at Test.main(Test.java:27)
org.hibernate.HibernateException: Errors in named queries: test3
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:364)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
at Test.main(Test.java:27)
java.lang.NullPointerException
at Test.main(Test.java:41):
oracle 9i:
My POJO is here
public class EmployeeVO implements Serializable{
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public EmployeeVO() {
super();
// TODO Auto-generated constructor stub
}
}
I am trying to call a named query
Thanks in advance