Reputation: 306
I have entities User and Report
class User {
@JoinColumn(name = "user_id")
protected Set<BattleReport> reports;
}
class Report {
byte data;
}
I know user id and I need to update report data for a User without loading user. How to do it?
I've tried this way, but it doesn't work:
Query reportsQuery = session.createQuery("SELECT reports FROM User WHERE id = :id");
reportsQuery.setParameter("id", id);
List<?> list = reportsQuery.list();
for (Object o : list) {
Report report = (Report) o;
report.setData(42);
session.update(report);
}
Upvotes: 0
Views: 167
Reputation: 306
The correct answer is:
SELECT u.reports FROM User u WHERE u.id = :id
Upvotes: 0
Reputation: 303
Have you tried doing a Criteria query on the Report table with the user_id as a constraint? I don't know youyr database relationship or fields and, as such, can't give you a real example, but something as follow can be userfull perhaps:
Upvotes: 0
Reputation: 425053
Match on the id of the user of the report:
Query reportsQuery = session.createQuery(
"FROM Report r WHERE r.user.id = :id");
Upvotes: 1