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 ">

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

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.