标签: hql-delete

用Hibernate HQL删除和

Hibernate不会删除我的行:

public boolean deleteVote(Login user, int pid){

      Session session = getSession();

      try{
          String hql = "delete from Vote where uid= :uid AND pid= :pid";
          Query query = session.createQuery(hql);
          System.out.println(user.getUid() + " and pid: " + pid);
          query.setString("uid", user.getUid());
          query.setInteger("pid", pid);
          System.out.println(query.executeUpdate());
      }catch(Exception e){
Run Code Online (Sandbox Code Playgroud)

Outprint:

uid: 123 and pid: 1
Hibernate: delete from votes where uid=? and pid=?
1
Run Code Online (Sandbox Code Playgroud)

当我在SQL中直接尝试时,SQL语法正在工作.直接SQL语法:

 delete from votes where uid= '123' AND pid= 1
Run Code Online (Sandbox Code Playgroud)

制图:

<class name="package.model.Vote" table="votes">
   <id name="vid" column="vid" >
   <generator class="increment"/>
</id>
<property …
Run Code Online (Sandbox Code Playgroud)

hibernate hql hql-delete

17
推荐指数
1
解决办法
8万
查看次数

Hibernate 4.1.11 hql删除查询与列表中的位置

我想从表中删除一些具有特定ID的条目.我想知道这个请求的语法

delete from table where id in list_of_ids
Run Code Online (Sandbox Code Playgroud)

在hql中.

hibernate hql hql-delete

6
推荐指数
2
解决办法
7141
查看次数

当具有相同术语的HQL选择有效时,为什么此HQL删除失败?

为什么以下HQL查询失败?

string hql = @"delete MyLog log
               where
                    log.UtcTimestamp < :threshold and
                    log.Configuration.Application = :application";

session.CreateQuery(hql)
       .SetDateTime("threshold", threshold)
       .SetEnum("application", this.application)
       .ExecuteUpdate();
Run Code Online (Sandbox Code Playgroud)

在select中使用相同形式的查询:

string hql = @"from MyLog log
               where
                    log.UtcTimestamp < :threshold and
                    log.Configuration.Application = :application";
IList<MyLog> log = session.CreateQuery(hql)
    .SetDateTime("threshold", threshold)
    .SetEnum("application", this.application)
    .List<MyLog>();
Run Code Online (Sandbox Code Playgroud)

MyLog的映射包含:

References(x => x.Configuration)
     .Columns("CONFIGURATION_ID")
     .ReadOnly();      
Run Code Online (Sandbox Code Playgroud)

Configuration的映射包含:

Map(x => x.Application, "APPLICATION_ID");
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

从MYLOG中删除,CONFIGURATION countercon1_,其中UTC_TIMESTAMP <:p0和APPLICATION_ID =:p1; :p0 = 04/10/2010 17:15:52,:p1 = 7

NHibernate.Exceptions.GenericADOException:无法执行更新查询[SQL:

从MYLOG,CONFIGURATION中删除countercon1_,其中UTC_TIMESTAMP <?和APPLICATION_ID =?

] ---> Oracle.DataAccess.Client.OracleException:ORA-00933:SQL命令未正确结束

nhibernate hql fluent-nhibernate ora-00933 hql-delete

3
推荐指数
1
解决办法
7918
查看次数

hql查询删除两个表中的记录

我的查询是。

Query query1 = session.createQuery(
                "DELETE Question, Answer FROM Question que LEFT JOIN Answer ans ON que.id=ans.questionId  WHERE que.quiz_type_id=:qtypeid");
        query1.setParameter("qtypeid", id);
        query1.executeUpdate();
Run Code Online (Sandbox Code Playgroud)

此查询不起作用...请帮助...

问题表

答案表

HTTP 状态 500 - 请求处理失败;嵌套异常是 org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记:,第 1 行附近,第 38 列 [DELETE com.online.test.model.Question, Answer FROM com.online.test.model.Question que LEFT JOIN Answer ans ON que.id=ans.questionId WHERE que.quiz_type_id=:qtypeid]

输入异常报告

消息请求处理失败;嵌套异常是 org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记:,第 1 行附近,第 38 列 [DELETE com.online.test.model.Question, Answer FROM com.online.test.model.Question que LEFT JOIN Answer ans ON que.id=ans.questionId WHERE que.quiz_type_id=:qtypeid]

说明 服务器遇到内部错误,无法完成此请求。

例外

org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记:,第 1 行附近,第 38 列 [DELETE …

hibernate hql hql-delete

2
推荐指数
1
解决办法
2416
查看次数