JPA/Eclipse TopLink の使用。
以下に示すように、(createNativeQuery を使用して) テーブルを更新しています。
Query query = em.createNativeQuery("UPDATE Products SET productName='" + p.getProductName() + "',productVendor='" + p.getProductVendor() + "',productDescription='" + p.getProductDescription() + "',quantityInStock=" + p.getQuantityInStock() + ",buyPrice =" + p.getBuyPrice() + ",msrp=" + p.getMsrp() + " WHERE productCode='" + p.getProductCode() + "'");
query.executeUpdate();
DB(MySQL)に更新が反映される
以下に示すように(createQueryを使用して)取得する場合:
Query query1 = em.createQuery("SELECT p from Products p where p.productCode='"+searchTerm+"'");
return query1.getResultList();
ただし、返される ResultList は常に更新前のデータです。しかし、createQuery の代わりに createNativeQuery を使用すると、最新の更新されたデータが返されます。createQuery メソッドで考えられるエラーは何ですか?