i need to update multiple rows in Table a and it seems ok to use the object oriented approach by using a for loop and doing a merge.
...
// get list and assign columns to be updated
...
for (MyEntity e : entityList) {
em.merge(e);
}
..
this approach also enables me to update other tables (as other property pf MyEntity). on one of the questions posted here updating multiple rows using JPA , the second option which uses a namedQuery to update seems to be faster. However how will the update be implemented if i need to batch update multiple tables as well?
i have tried:
@NamedQuery(name="Agent.updateAccountStatusByTree",
query="UPDATE com.sample.core.data.Agent a "
+ "INNER JOIN com.sample.core.data.Player p "
+ "ON a.player.id = p.id "
+ "SET a.accountStatus=:accountStatus, p.status=:accountStatus "
+ "WHERE a.site.id=:siteId and a.agentTree like :agentTree")})
however this throws a:
org.hibernate.hql.ast.QuerySyntaxException: expecting "set", found 'INNER'
another option which i tried is:
@NamedQuery(name="Agent.updateAccountStatusByTree",
query="update com.sample.core.data.Agent a "
+ "set a.accountStatus=:accountStatus, a.player.status=:playerStatus "
+ "where a.site.id=:siteId and a.agentTree like :agentTree")})
since i already have a refer to the other table, however this generates an invalid query throwing a sql grammar exception... is there any other way to achieve this?
Thanks.