Java HQL org.hsqldb.HsqlException:用户缺少权限或找不到对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25402160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 07:57:41  来源:igfitidea点击:

Java HQL org.hsqldb.HsqlException: user lacks privilege or object not found

javaspringhibernatehqlhsqldb

提问by user

I am using Spring 3 with Hibernate 3. I am using the DAO design pattern and using HQL to query the database. However, when searching for data that does not exist for a field I get the following Exception:

我使用 Spring 3 和 Hibernate 3。我使用 DAO 设计模式并使用 HQL 查询数据库。但是,在搜索字段中不存在的数据时,出现以下异常:

org.hsqldb.HsqlException: user lacks privilege or object not found: ADDRESS2

I am using Liquidbase to manage the database XML schema that creates the tables. Below is the sample code:

我正在使用 Liquidbase 来管理创建表的数据库 XML 模式。下面是示例代码:

@Entity
@Table(name = "message")
public class Message() {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    @Column(length = 100, nullable = false)
    private String address;

    public Message() {

    }

    // getters and setters
}

The following HQL is used from the DAO:

DAO 中使用了以下 HQL:

 getHibernateTemplate().find("FROM Message m WHERE m.address = address2");

The following properties are being set:

正在设置以下属性:

jdbc.driverClassName=org.hsqldb.jdbc.JDBCDriver
jdbc.url=jdbc:hsqldb:mem:testdb'shutdown=true
jdbc.username=sa
jdbc.password=
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=validate

I cannot find a solution. I can successfully insert a record and also use the same HQL query to find objects with actual values that have been saved, but the problem is with finding values that don't exist.

我找不到解决办法。我可以成功插入一条记录,也可以使用相同的 HQL 查询来查找具有已保存实际值的对象,但问题在于查找不存在的值。

采纳答案by JB Nizet

FROM Message m WHERE m.address = address2

This query looks for messages whoses addressfield is equal to their address2field. But messages don't have an address2field. If your intention is to find all messages whose addressfield has the value "address2", then the query is

此查询查找addressaddress2字段等于其字段的消息。但是消息没有address2字段。如果您的目的是查找address字段值为“address2”的所有消息,则查询为

FROM Message m WHERE m.address = 'address2'

回答by Laurence Geng

try:

尝试:

 getHibernateTemplate().find("FROM Message m WHERE m.address = 'address2'");

回答by Nandlal

Check your Database URL:

检查您的数据库 URL:

You may need to put the full path of database

你可能需要把数据库的完整路径

For example, jdbc:hsqldb:file:C:/Users/10617136/dev/hsqldb-2.3.2/hsqldb/bin/test

例如 jdbc:hsqldb:file:C:/Users/10617136/dev/hsqldb-2.3.2/hsqldb/bin/test

回答by Joy

I feel wired. After I changed my field name from profileImageto image, i.e., making it all lowercase, the problem is solved.

我觉得有线。把我的字段名从profileImage改为 后image,即全部小写,问题就解决了。