gpt4 book ai didi

带内连接的 Hibernate 更新查询

转载 作者:行者123 更新时间:2023-12-04 12:23:00 25 4
gpt4 key购买 nike

我有以下带有内部连接的 MySQL 更新查询:

 UPDATE Country AS c
INNER JOIN State s ON c.CountryID = s.CountryID
INNER JOIN City cy On s.StateID = cy.StateID
SET c.Active='Y', s.Active='Y',cy.Active='Y'
WHERE c.CountryID='12'

这是我的国家 map 类
enter code here
@Entity
@Table(name = "Country")
public class Country {
public Country() {
}

@Id
@Column(name = "CountryID")
private String countryID;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "country")
private Set<State> state = new HashSet<State>(0);

@Column(name = "CountryName")
private String countryName;
}

状态的 Mpping 类
 @Entity
@Table(name = "State")
public class State {
public State() {
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "countryID", nullable = false)
private Country country;

public Country getCountry() {
return country;
}

public void setCountry(Country country) {
this.country = country;
}

@Id
@Column(name = "StateID")
private String stateID;

@Column(name = "CountryID")
private String countryID;

@Column(name = "StateName")
private String stateName;

我如何用 hibernatye 语言编写相同的查询。请任何人帮助我。
我已经尝试了很多,但我做不到。

谢谢

最佳答案

你不能。 HQL 更新查询不能有连接。见 the documentation :

Some points to note:

  • [...]
  • No joins, either implicit or explicit, can be specified in a bulk HQL query.

关于带内连接的 Hibernate 更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13467024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com