I have the following MySQL update query with inner join:
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'
Here is my country mapping class
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 class for State
@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;
How can i write the same query in hibernatye language.can any one please help me. i have tried a lot but i can't make it.
Thanks
You can't. HQL update queries can't have joins. See the documentation:
Some points to note:
- [...]
- No joins, either implicit or explicit, can be specified in a bulk HQL query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With