title: org.hibernate.MappingException: Unknown entity: java.lang.Long
body: <p>I am trying to create a named-native-query that returns a Long.</p>
  
  <p>Here is my orm.xml file (simplified as much as possible)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  
  &lt;named-native-query name="getCaseNumberByCommId" result-class="java.lang.Long"&gt;
    &lt;query&gt;SELECT case_id FROM communications WHERE comm_id =(?1)&lt;/query&gt;
  &lt;/named-native-query&gt;
  
  &lt;/entity-mappings&gt;
  </code></pre>
  
  <p>this is the error I get: </p>
  
  <p>ERROR - org.hibernate.impl.SessionFactoryImpl - Error in named query: getCaseNumberByCommId
  [coral:launch] org.hibernate.MappingException: Unknown entity: java.lang.Long</p>
  
  <p>I've also tried just specifying "Long"</p>
  
  <pre><code>&lt;named-native-query name="getCaseNumberByCommId" result-class="Long"&gt;
    &lt;query&gt;SELECT case_id FROM communications WHERE comm_id =(?1)&lt;/query&gt;
  &lt;/named-native-query&gt;
  </code></pre>
  
  <p>and strangely get this error:</p>
  
  <p>Caused by: org.hibernate.AnnotationException: Unable to find entity-class: Long
  ...
   Caused by: java.lang.ClassNotFoundException: Long</p>
  
  <p>Java can't find Long in java.lang?  </p>
  
  <p>Thank you for any clues</p>
  
  <p><strong>edit</strong>:  I tried removing the 'result-class' annotation :</p>
  
  <pre><code>    &lt;named-native-query name="getCaseNumberByCommId" &gt;
          &lt;query&gt;SELECT case_id FROM communications WHERE comm_id =(?1)&lt;/query&gt;
      &lt;/named-native-query&gt;
  </code></pre>
  
  <p>and get this error:</p>
  
  <p>nested exception is org.hibernate.cfg.NotYetImplementedException: Pure native scalar queries are not yet supported</p>
  
  <p><em><strong>Update</em>*</strong></p>
  
  <p>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.</p>
  
  <p>e.g.</p>
  
  <pre><code>    &lt;named-native-query name="getByCommId" result-class="com.foo.model.Communication"&gt;
          &lt;query&gt;SELECT * FROM communications WHERE comm_id =(?1)&lt;/query&gt;
      &lt;/named-native-query&gt;
  </code></pre>
  
  <p>and then pull the desired case_id out of the returned pojo.</p>