org.hibernate.hql.ast.QuerySyntaxException:表未映射

bur*_*ing 2 java hibernate restlet-2.0

我知道很多人都问过这个问题,但我刚开始使用Java,所以我还是想不通.

所以这是我的问题:我正在使用RESTful webservices Javarestlet.这是我的DAO文件的片段.

try {

            session.beginTransaction();

            String query = "select number from   blockedcli";
            @SuppressWarnings("rawtypes")
            List list = session.createQuery(query).list(); //.setString("sId", businessId)


            logger.error("*******************list*****************************************");
            logger.error(list);
            logger.error("*******************listend*****************************************");


            @SuppressWarnings("rawtypes")
            Iterator iterator = list.iterator();

            while (iterator.hasNext()) {

                blockedcli = (BlockedCli) iterator.next();
            }
            session.getTransaction().commit();
        } 
Run Code Online (Sandbox Code Playgroud)

相应地,我的实体类看起来像.

@Entity
@Table(name = "blockedcli")
public class BlockedCli implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="idBlockedCLI", nullable = false, unique=true)
    private Integer idBlockedCLI;

    @Column(name = "number",nullable = false, length=45)
    private String number;

    @Column(name = "type", nullable = false)
    private Integer type;
    .
Run Code Online (Sandbox Code Playgroud)

BlackListedN.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="tecd.persistence.entity.BlockedCli" table="blockedcli">    
    <id name="idBlockedCLI" type="long" unsaved-value="null">
        <column name="idBlockedCLI" not-null="true"/>
        <generator class="identity"/>
    </id>
        <property name="number">
            <column name="number" not-null="true" />
        </property>
    </class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)

因为我只想显示数字.

这是DB表.

+--------------+--------------+--------+------+---------------------+---------------------+---------------------------------------+
| idBlockedCLI | number       | status | type | createdDT           | updatedDT           | BusinessDirectory_idBusinessDirectory |
+--------------+--------------+--------+------+---------------------+---------------------+---------------------------------------+
|            1 | 919845611234 |      1 |    1 | 2014-03-24 13:31:20 | 2014-03-24 13:31:20 | 1                                     |
+--------------+--------------+--------+------+---------------------+---------------------+---------------------------------------+
Run Code Online (Sandbox Code Playgroud)

但是当我每次都跑这个时,它说

org.hibernate.hql.ast.QuerySyntaxException: blockedcli is not mapped [select number from   blockedcli]
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题.

这是我的第一个Java程序,所以我不确定还需要详细说明这些内容,但是如果需要其他任何内容,请告诉我.

Ale*_*øld 7

使用HQL时,需要引用正确大写的实体名称/属性,而不是表名/列名.只需将您的查询更改为select number from BlockedCli,它应该有效.