my error was :o Org.hibernate.hql.ast.QuerySyntaxException:DEPT is notmapped [from DEPT]
The configuration file is as follows:
<?xml version="1.0"? ><! DOCTYPE hibernate-Mapping Public"-//hibernate/hibernate Mapping DTD 3.0//en" "HTTP://WWW.HIBERNATE.ORG/DTD/HIBERNATE-MAPPING-3.0.DTD">"cn.lex.entity"> <className="Dept"table="DEPT"> <id name="Deptno"column="Deptno"> <generatorclass="native"/> </id> <property name="dname"></property> <property name="Loc"></property> </class>Mapping>
The code is as follows:
Package Cn.lex.test;import Cn.lex.entity.dept;import org.hibernate.query;import org.hibernate.session;import Org.hibernate.sessionfactory;import Org.hibernate.transaction;import Org.hibernate.cfg.configuration;import Org.junit.after;import org.junit.before;import org.junit.test;import java.util.List;/** * Created by ACCP on 2017/1/9.*/ Public classSecondtest {Session session; Transaction TX; @Before Public voidbefore () {Configuration cfg=NewConfiguration (). Configure (); Sessionfactory Factory=cfg.buildsessionfactory (); Session=factory.opensession (); TX=session.begintransaction (); } @Test Public voidpage () {String hql="From DEPT ORDER by DEPTNO"; //Create a Query objectQuery query =session.createquery (HQL); //show several data per page intPagesize=2; //set the first page intpageindex=1; //set the maximum number of records to display per pagequery.setmaxresults (pageSize); //setting the output from the first fewQuery.setfetchsize ((pageindex-1)*pageSize); List<Dept> list =query.list (); for(Dept dept:list) {System. out. println ("Department Number:"+Dept.getdeptno ()); }} @After Public voidAfter () {tx.commit (); Session.close (); }}
The root cause of this error is that the HQL syntax is a pojo (Plain ordinary Java Object) object instead of a table. So change it to this:
List<dept> list=session.createquery ("fromDept order by DEPTNO"). List ();
It's written here! In case you don't forget!
is not mapped error correction