我有 3 个表 UserDetail、RequestorDetail 和 AddressDetail。 UserDetail 具有 userId(PK)、userName,AddressDetail 具有城市和郊区,RequestorDetail 具有 reqEmail 和 reqPhone。
我想使用一个查询更新所有这些详细信息。截至目前,我正在使用如下 3 个不同的查询。
@Modifying
@Query("update UserDetail u set "u.userName = :userName, u.password = :password where u.userEmailId = :userEmailId")
int saveUserDetailData(@Param("userName") String userName, @Param("password") String password, @Param("userEmailId") String userEmailId);
@Modifying
@Query("update RequestorDetail r set r.requestorEmailid = :requestorEmailid, r.requestorPhone = :requestorPhone where r.userId = :userId")
int saveRequestorDetailData(@Param("requestorEmailid") String requestorEmailid,
@Param("requestorPhone") String requestorPhone, @Param("userId") int userId);
@Modifying
@Query("update AddressDetail a set a.city = :city, a.suburb = :suburb where a.userId = :userId")
int saveAddressDetailData(@Param("city") String city, @Param("suburb") String suburb,
@Param("userId") int userId);
谁能告诉我如何在单个查询中使用所有这些?
最佳答案
不可能使用单个 SQL 查询更新多个表。 请参阅https://community.oracle.com/thread/2225393
您必须将其拆分为不同的查询。
关于mysql - 如何在 JPA 中使用一个查询更新 3 个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37594131/