I am trying to create a named-native-query that returns a Long.
Here is my orm.xml file (simplified as much as possible)
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings 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_2_0.xsd"
version="2.0">
<named-native-query name="getCaseNumberByCommId" result-class="java.lang.Long">
<query>SELECT case_id FROM communications WHERE comm_id =(?1)</query>
</named-native-query>
</entity-mappings>
this is the error I get:
ERROR - org.hibernate.impl.SessionFactoryImpl - Error in named query: getCaseNumberByCommId [coral:launch] org.hibernate.MappingException: Unknown entity: java.lang.Long
I've also tried just specifying "Long"
<named-native-query name="getCaseNumberByCommId" result-class="Long">
<query>SELECT case_id FROM communications WHERE comm_id =(?1)</query>
</named-native-query>
and strangely get this error:
Caused by: org.hibernate.AnnotationException: Unable to find entity-class: Long ... Caused by: java.lang.ClassNotFoundException: Long
Java can't find Long in java.lang?
Thank you for any clues
edit: I tried removing the 'result-class' annotation :
<named-native-query name="getCaseNumberByCommId" >
<query>SELECT case_id FROM communications WHERE comm_id =(?1)</query>
</named-native-query>
and get this error:
nested exception is org.hibernate.cfg.NotYetImplementedException: Pure native scalar queries are not yet supported
Update*
I never did find a way to do this, but since the database had a uniqueness constraint on comm_id, I was able to just return a mapped pojo object instead of a count.
e.g.
<named-native-query name="getByCommId" result-class="com.foo.model.Communication">
<query>SELECT * FROM communications WHERE comm_id =(?1)</query>
</named-native-query>
and then pull the desired case_id out of the returned pojo.