Skip to content
Advertisement

Update statement is no query?

How do I define the update statement in the orm.xml. I have it as a named-query and everything works, but my teacher said that an update statement isn’t a query. I have tried a native query, but that wasn’t working.

ORM-Type:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="1.0"
    xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd">

Update Statement:

<named-query name="updateTshirts">
    <query>
        update Tshirt tshirt Set tshirt.bEdit = :bedit, tshirt.farbe = :farbe,
        tshirt.groesse = :groesse, tshirt.markenName = :markenname where
        tshirt.tID = :tid
    </query>
</named-query>

Advertisement

Answer

The term “query” is used rather ambiguously. Some people interpret it literally as “asking for information”, meaning only select statements or other things producing a result set fall under this term, while others interpret it more broadly as any DML (Data Manipulation Language, i.e. select, insert, update, delete, merge, etc) statement.

Your teacher seems to fall in the first category, while the people who created the Jakarta Persistence API (JPA) fall into the second category. So, in a sense you’re both right, in the first interpretation, an update statement is not a “query”, but in the second interpretation, which is used by JPA, it is a “query”.

However, given the context, your interpretation is the better one.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement