is not mapped error correction

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.