I have a many to many between customer/reservation. getReservations has a cascade of REFRESH. When I execute the following code, the custoemr Bill has multiple reservations listed after the update. It looks like the collection is not being cleared before the refresh.
Customer bill = (Customer)manager.createQuery("FROM Customer c " + "where c.firstName = 'Bill' and " + "c.lastName='Burke'").getSingleResult(); Collection<Reservation> reservations = bill.getReservations(); for (Reservation res : reservations) { System.out.println("amountPaid: " + res.getAmountPaid()); }
Query query; query = manager.createQuery("UPDATE Reservation res " + "SET res.amountPaid = (res.amountPaid + 10) " + "WHERE EXISTS (" + "SELECT c FROM res.customers c " + "where c.firstName = 'Bill' and " + "c.lastName='Burke')"); query.executeUpdate(); manager.flush(); System.out.println("Show all amount paid for all of Bill's reservations after update:"); /* bill = (Customer)manager.createQuery("FROM Customer c " + "where c.firstName = 'Bill' and " + "c.lastName='Burke'").getSingleResult(); */ manager.refresh(bill); reservations = bill.getReservations(); for (Reservation res : reservations) { System.out.println("amountPaid: " + res.getAmountPaid()); }
Attachments
1
Activity
Show:
Brett Meyer July 8, 2014 at 3:11 PM
Bulk rejecting stale issues. If this is still a legitimate issue on ORM 4, feel free to comment and attach a test case. I'll address responses case-by-case. Thanks!
If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.
I have a many to many between customer/reservation. getReservations has a cascade of REFRESH. When I execute the following code, the custoemr Bill has multiple reservations listed after the update. It looks like the collection is not being cleared before the refresh.
Customer bill = (Customer)manager.createQuery("FROM Customer c " +
"where c.firstName = 'Bill' and " +
"c.lastName='Burke'").getSingleResult();
Collection<Reservation> reservations = bill.getReservations();
for (Reservation res : reservations)
{
System.out.println("amountPaid: " + res.getAmountPaid());
}
Query query;
query = manager.createQuery("UPDATE Reservation res " +
"SET res.amountPaid = (res.amountPaid + 10) " +
"WHERE EXISTS (" +
"SELECT c FROM res.customers c " +
"where c.firstName = 'Bill' and " +
"c.lastName='Burke')");
query.executeUpdate();
manager.flush();
System.out.println("Show all amount paid for all of Bill's reservations after update:");
/*
bill = (Customer)manager.createQuery("FROM Customer c " +
"where c.firstName = 'Bill' and " +
"c.lastName='Burke'").getSingleResult();
*/
manager.refresh(bill);
reservations = bill.getReservations();
for (Reservation res : reservations)
{
System.out.println("amountPaid: " + res.getAmountPaid());
}