OPENJPA-1112 JPA2 Query result of embeddable object can not be further updated

Bulk update of embedded field is not allowed

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@806675 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Catalina Wei 2009-08-21 18:53:40 +00:00
parent 382bafc874
commit 2615a9b426
3 changed files with 31 additions and 1 deletions

View File

@ -558,6 +558,10 @@ public class JPQLExpressionBuilder
JPQLNode[] nodes = root().findChildrenByID(JJTUPDATEITEM);
for (int i = 0; nodes != null && i < nodes.length; i++) {
Path path = getPath(firstChild(nodes[i]));
if (path.last().getValue().getEmbeddedMetaData() != null)
throw parseException(EX_USER, "cant-bulk-update-embeddable",
new Object[]{assemble(firstChild(nodes[i]))}, null);
JPQLNode lastChild = lastChild(nodes[i]);
Value val = (lastChild.children == null)
? null : getValue(onlyChild(lastChild));

View File

@ -79,4 +79,7 @@ bad-qualified-path: Attemp to navigate a basic type of Key("{0}").
bad-general-identifier: The identitier "{0}" in "{1}" operator is not valid \
in conditional expression.
bad-predicate: JPQL query does not support conditional expression over \
embeddable class. JPQL string: "{0}".
embeddable class. JPQL string: "{0}".
cant-bulk-update-embeddable: Bulk update of embeddable field is not allowed: \
"{0}".

View File

@ -84,6 +84,29 @@ public class TestUpdateEmbeddedQueryResult extends SingleEMFTestCase {
return embed;
}
/*
*
*/
public void testBulkUpdateEmbeddedField() {
EntityManager em = emf.createEntityManager();
String update = "UPDATE EntityA_Embed_Embed a set a.embed.embed.intVal1 = ?1," +
" a.embed.embed.intVal2 = ?2 where a.id = 10";
em.getTransaction().begin();
int count = em.createQuery(update).setParameter(1, 100).setParameter(2, 200).executeUpdate();
em.getTransaction().commit();
assertEquals(count, 0);
// test invalid bulk update embeddable field
update = "UPDATE EntityA_Embed_Embed a set a.embed.embed = ?1";
Embed embed1 = createEmbed(ID, 10);
try {
int updateCount = em.createQuery(update).setParameter(1, embed1).executeUpdate();
} catch (ArgumentException e) {
// as expected: Bulk update of embeddable field is not allowed.
}
em.close();
}
/*
* update embedded object returned from query
*/