-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: named-native-query in orm.xml
PostPosted: Wed Dec 17, 2008 4:31 pm 
Newbie

Joined: Thu Mar 22, 2007 3:03 am
Posts: 5
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 8:42 pm 
Newbie

Joined: Wed Dec 17, 2008 6:35 pm
Posts: 11
I got that error the first time i tried to do an IN clause in a named query. I think it's the (). I wrapped my query in this CDATA tag and its working for me.

Code:
<sql-query name="myNamedQuery"><![CDATA[
SELECT something FROM table
]]></sql-query>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 7:57 pm 
Newbie

Joined: Thu Mar 22, 2007 3:03 am
Posts: 5
I did wrap the query with CDATA. Same error.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.