我的错误提示为
org.hibernate.hql.ast.QuerySyntaxException: LIBRARY is not mapped [select l from LIBRARY as l order by l.id]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)数据库的表叫LIBRARY,有三个字段ID,TITLE,CONTENT,其中ID为主键
关键代码为
model.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
       
<hibernate-mapping>
<class name="hbm.DVDItem" table="LIBRARY">
<id name="id" type="int" column="ID" >
<generator class="native"/>
</id>
<property name="title"  column="TITLE"/>
<property name="content" column="CONTENT" />
</class>
</hibernate-mapping>javabean放在hbm包内
package hbm;
public class DVDItem {
private int id;
private String title;
private String content; public DVDItem(){} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
}}
在代码中用到了查询语句为select l from LIBRARY as l order by l.id
不知道哪映射错了,麻烦大家帮我看看 谢谢

解决方案 »

  1.   

    from DVDItem as l order by l.id
      

  2.   

    HQL
    在form后面跟的是类名。不是表名
      

  3.   


    <hibernate-mapping>
        <class name="hbm.DVDItem" table="LIBRARY">
            <id name="id" type="int" column="ID" >
                <generator class="native"/>
            </id>
            <property name="title"  column="TITLE"/>
            <property name="content" column="CONTENT" />
        </class>
    </hibernate-mapping> <class name="hbm.DVDItem" table="LIBRARY">
            <id name="id" type="java.lang.Long">
                <column name="ID" precision="22" scale="0" />
                <generator class="native" />
            </id>
            <property name="title" type="java.lang.String">
                <column name="TITLE" />
            </property>
            <property name="content" type="java.lang.String">
                <column name="CONTENT" />
            </property>
        </class>
      

  4.   

    你用的session.createQuery() 就得用DVDItem---------------------hql
    你用的session.createSQLQuery()就得用数据库中表名了
      

  5.   

    LIBRARY is not mapped  [select l from LIBRARY as l order by l.id]
     很明显 这个类LIBRARY 没有被映射 
    还有就是在HQL语句里面 用的不是数据库表的名字 而是与之相对应的Entity,属性也是 也应该是Entity的属性 不是数据库列的名字