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 ">
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 class Secondtest {session session; Transaction TX; @Before public void before () {Configuration cfg=new configuration (). Configure (); Sessionfactory factory=cfg.buildsessionfactory (); Session=factory.opensession (); Tx=session.begintransaction (); } @Test public void page () {String hql= ' from DEPT order by DEPTNO '; Create a Query object query query = session.createquery (HQL); Each page shows several data int pagesize=2; Set the first page int pageindex=1; Sets the maximum number of records displayed per page query.setmaxresults (pageSize); Set the output from the first query.setfetchsize ((pageIndex-1) *pagesize); List<dept> list = Query.list (); for (Dept dept:list) {System.out.println ("department Number:" +dept.getdeptno ()); }} @After public void after () {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 ("from Dept Order by DEPTNO"). List ();
It's written here! In case you don't forget!
is not mapped error correction