使用innerjoin进行Hibernate更新查询

eda*_*lij 7 hibernate inner-join hibernate-mapping hibernate-criteria

我有内部联接的以下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'
Run Code Online (Sandbox Code Playgroud)

这是我的国家地图类

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;
}
Run Code Online (Sandbox Code Playgroud)

国家的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;
Run Code Online (Sandbox Code Playgroud)

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

谢谢

JB *_*zet 5

你不能.HQL更新查询不能有联接.查看文档:

有些要点需要注意:

  • [...]
  • 在批量HQL查询中不能指定隐式或显式的连接.