我执行下面的HQL时遇到[42000] You have an error in your SQL syntax
错误:
update Status set result=18 where (userByUserId.userName like 'administrator')
这是相应的SQL:
update
status cross
join
set
result=18
where
userName like 'administrator'
我得到的结果不正确。
但是另一个类似的查询正在运行:
select count(*) from Status where (userByUserId.userName like 'administrator')
相应的SQL:
select
count(*) as col_0_0_
from
status status0_ cross
join
user user1_
where
status0_.userId=user1_.userId
and (
user1_.userName like 'administrator'
)
有谁知道发生了什么?
这是代码(部分):
Status.java
@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
@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;
}
}