Hi,
I would like to move the following native query from my code to orm.xml. It works when it's defined in the code, but not in the orm.xml.
Code:
// this works
public void writeAudit(String username) {
getEntityManager().createNativeQuery("insert into audit_table (username) values (?)").setParameter(1, username);
}
tried:
Code:
public void writeAudit(String username) {
getEntityManager().createNamedQuery("writeAudit").setParameter(1, username);
}
orm.xml:
Code:
1)
<entity-mappings>
<named-native-query name="writeAudit">
<query>insert into audit_table (username) values (?)</query>
</named-native-query>
</entity-mappings>
2)
<entity-mappings>
<named-native-query name="writeAudit" result-class="java.lang.Long">
<query>insert into audit_table (username) values (?)</query>
</named-native-query>
</entity-mappings>
11:52:02,418 ERROR XMLHelper: Error parsing XML: XML InputStream(115) cvc-comple
x-type.2.4.a: Invalid content was found starting with element 'named-query'. One
of '{"http://java.sun.com/xml/ns/persistence/orm":named-native-query, "http://j
ava.sun.com/xml/ns/persistence/orm":sql-result-set-mapping, "http://java.sun.com
/xml/ns/persistence/orm":mapped-superclass, "http://java.sun.com/xml/ns/persiste
nce/orm":entity, "http://java.sun.com/xml/ns/persistence/orm":embeddable}' is ex
pected.
According to
http://java.sun.com/xml/ns/persistence/orm_1_0.xsd, named-native-query should accept a result-class attribute. Also, I'm doing an insert I really don't care about the return result.
I have used named-native-query in orm.xml before with TopLink with a select instead of and insert and didn't run into any issue.
hibernate-3.2.6.ga.jar
hibernate-annotations-3.3.1.GA.jar
hibernate-commons-annotations-3.0.0.ga.jar
hibernate-entitymanager-3.3.2.GA.jar