java - org.hibernate.hql.internal.ast.QuerySyntaxException: table is not mapped -


i have example web application hibernate 4.3.5 + derby database 10.10.1.1+ glassfish4.0 ide netbeans 8.0beta.

i have next exception:

caused by: org.hibernate.hql.internal.ast.querysyntaxexception: customerv not mapped @ org.hibernate.hql.internal.ast.util.sessionfactoryhelper.requireclasspersister(sessionfactoryhelper.java:189) @ org.hibernate.hql.internal.ast.tree.fromelementfactory.addfromelement(fromelementfactory.java:109) @ org.hibernate.hql.internal.ast.tree.fromclause.addfromelement(fromclause.java:95) @ org.hibernate.hql.internal.ast.hqlsqlwalker.createfromelement(hqlsqlwalker.java:331) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.fromelement(hqlsqlbasewalker.java:3633) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.fromelementlist(hqlsqlbasewalker.java:3522) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.fromclause(hqlsqlbasewalker.java:706) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.query(hqlsqlbasewalker.java:562) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.selectstatement(hqlsqlbasewalker.java:299) @ org.hibernate.hql.internal.antlr.hqlsqlbasewalker.statement(hqlsqlbasewalker.java:247) @ org.hibernate.hql.internal.ast.querytranslatorimpl.analyze(querytranslatorimpl.java:278) @ org.hibernate.hql.internal.ast.querytranslatorimpl.docompile(querytranslatorimpl.java:206) ... 72 more  

form index.xhtml

<h:panelgrid id="panel1" columns="2" border="1"                  cellpadding="5" cellspacing="1">         <f:facet name="header">             <h:outputtext value="add customer information"/>         </f:facet>         <h:outputlabel value="first name:"/>         <h:inputtext value="#{customer.firstname}" id="fn"/>         <h:outputlabel value="last name:"/>         <h:inputtext value="#{customer.lastname}" id="ln"/>         <h:outputlabel value="email:"/>         <h:inputtext value="#{customer.email}" id="eml"/>         <h:outputlabel value="date of birth:"/>         <h:inputtext value="#{customer.sd}" id="s"/>         <f:facet name="footer">             <h:outputlabel value="#{customer.msg}" id="msg" styleclass="msg"/>             <h:commandbutton value="save" action="#{customer.savecustomer}">             </h:commandbutton>         </f:facet>     </h:panelgrid>  

customer.java

    package com.javaknowledge.entity;      import com.javaknowledge.dao.customerdao;     import java.text.parseexception;     import java.text.simpledateformat;     import java.util.arraylist;     import java.util.date;     import java.util.list;     import javax.faces.bean.managedbean;     import javax.faces.bean.sessionscoped;     import javax.persistence.*;          @managedbean     @sessionscoped      public class customer implements java.io.serializable {      private integer custid;     private string firstname;     private string lastname;     private string email;     private date dob;     private string sd, msg, selectedname;     simpledateformat sdf = new simpledateformat("yyyy-mm-dd");       public customer() {     }      public customer(string firstname, string lastname, string email, date dob) {         this.firstname = firstname;         this.lastname = lastname;         this.email = email;         this.dob = dob;     }      public string getsd() {         return sd;     }      public void setsd(string sd) {         this.sd = sd;     }      public integer getcustid() {         return this.custid;     }      public void setcustid(integer custid) {         this.custid = custid;     }      public string getfirstname() {         return this.firstname;     }      public void setfirstname(string firstname) {         this.firstname = firstname;     }      public string getlastname() {         return this.lastname;     }      public void setlastname(string lastname) {         this.lastname = lastname;     }     @column(name = "email")     public string getemail() {         return this.email;     }      public void setemail(string email) {         this.email = email;     }      @column(name = "dob")     public date getdob() {         return this.dob;     }      public void setdob(date dob) {         this.dob = dob;     }      public string getmsg() {         return msg;     }      public void setmsg(string msg) {         this.msg = msg;     }      public string getselectedname() {         return selectedname;     }      public void setselectedname(string selectedname) {         this.selectedname = selectedname;     }      public void savecustomer() {         try {             date d = sdf.parse(sd);             system.out.println(d);             this.dob = d;         } catch (parseexception e) {             e.printstacktrace();         }         customerdao dao = new customerdao();         dao.addcustomer(this);         this.msg = "member info saved successfull!";         clearall();     }     public void updatecustomer() {         try {             date d = sdf.parse(sd);             system.out.println(d);             this.dob = d;         } catch (parseexception e) {             e.printstacktrace();         }         customerdao dao = new customerdao();         dao.updatecustomer(this);         this.msg = "member info update successfull!";         clearall();     }     public void deletecustomer() {         customerdao dao = new customerdao();         dao.deletecustomer(custid);         this.msg = "member info delete successfull!";         clearall();     }      public list<customer> getallcustomers() {         list<customer> users = new arraylist<customer>();         customerdao dao = new customerdao();         users = dao.getallcustomers();         return users;     }      public void fullinfo() {         customerdao dao = new customerdao();         list<customer> lc = dao.getcustomerbyid(selectedname);         system.out.println(lc.get(0).firstname);         this.custid = lc.get(0).custid;         this.firstname = lc.get(0).firstname;         this.lastname = lc.get(0).lastname;         this.email = lc.get(0).email;         this.dob = lc.get(0).dob;         this.sd = sdf.format(dob);     }      private void clearall() {         this.firstname = "";         this.lastname = "";         this.sd = "";         this.email = "";         this.custid=0;     }     } 

hibernate.cfg.xml

<?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>     <property name="hibernate.dialect">org.hibernate.dialect.derbydialect</property>     <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.clientdriver</property>     <property name="hibernate.connection.url">jdbc:derby://localhost:1527/derbydb</property>     <property name="hibernate.connection.username">user1</property>     <property name="hibernate.connection.password">user1</property>     <property name="hibernate.hbm2ddl.auto">create</property>      <property name="c3p0.min_size">1</property>     <property name="c3p0.max_size">5</property>     <property name="c3p0.timeout">300</property>     <property name="c3p0.max_statements">50</property>     <property name="c3p0.idle_test_period">300</property>      <mapping class="com.javaknowledge.entity.customer" resource="com/javaknowledge/entity/customer.hbm.xml"/>   </session-factory> </hibernate-configuration> 

customer.hbm.xml

<?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.javaknowledge.entity.customer" table="customerv" schema="app">         <id name="custid" type="java.lang.integer">             <column name="cust_id" />             <generator class="increment" />         </id>         <property name="firstname" type="string">             <column name="first_name" length="45" not-null="true" />         </property>         <property name="lastname" type="string">             <column name="last_name" length="45" not-null="true" />         </property>         <property name="email" type="string">             <column name="email" length="45" not-null="true" />         </property>         <property name="dob" type="date">             <column name="dob" length="10" not-null="true" />         </property>    </class> </hibernate-mapping> 

finally found mistake! hope useful someone. when doing request database(in case apache derby), name of base need write first letter upper case other in lower case.

this wrong query:

session.createquery("select first_name customerv"). 

this valid query

session.createquery("select first_name customerv").  

and class entity must same name database, i'm not sure.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -