-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HQL generated a incorrect SQL query
PostPosted: Wed Jan 15, 2014 6:29 am 
Newbie

Joined: Wed Jan 15, 2014 6:25 am
Posts: 1
I got [42000] You have an error in your SQL syntax error when I execute the HQL below:
Code:
update Status set result=18 where (userByUserId.userName like 'administrator')

And this is the corresponding SQL:
Code:
update
    status cross
join

set
    result=18
where
    userName like 'administrator'
The results I am getting are incorrect.


But another similar query is in working order:
Code:
select count(*) from Status where (userByUserId.userName like 'administrator')


the corresponding SQL:
Code:
select
    count(*) as col_0_0_
from
    status status0_ cross
join
    user user1_
where
    status0_.userId=user1_.userId
    and (
        user1_.userName like 'administrator'
    )

Does anyone knows what happened?

Here is the code(partly):

Status.java

Code:
@Table(name = "status")
@Entity
@KeyField("statusId")
public class Status implements Serializable {
  private Integer result;

  @Column(name = "result", nullable = false, insertable = true, updatable = true
      , length = 10, precision = 0)
  @Basic
  public Integer getResult() {
    return result;
  }

  private Integer userId;

  @Column(name = "userId", nullable = false, insertable = true, updatable = true
    , length = 10, precision = 0)
  public Integer getUserId() {
    return userId;
  }

  public void setUserId(Integer userId) {
    this.userId = userId;
  }

  private User userByUserId;

  @ManyToOne(cascade = CascadeType.ALL)
  @JoinColumn(name = "userId", referencedColumnName = "userId", nullable = false,
      insertable = false, updatable = false)
  public User getUserByUserId() {
    return userByUserId;
  }
}


User.java
Code:
@Table(name = "user")
@Entity
@KeyField("userId")
public class User implements Serializable {

  private String userName;

  @Column(name = "userName", nullable = false, insertable = true, updatable = true, length = 24,
    precision = 0, unique = true)
  @Basic
  public String getUserName() {
    return userName;
  }

  private Collection<Status> statusesByUserId;

  @OneToMany(mappedBy = "userByUserId", cascade = CascadeType.ALL)
  public Collection<Status> getStatusesByUserId() {
    return statusesByUserId;
  }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.