-->
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.  [ 1 post ] 
Author Message
 Post subject: Named queries returns java.lang.Object instead correct class
PostPosted: Wed Mar 23, 2011 11:10 am 
Newbie

Joined: Wed Mar 23, 2011 10:57 am
Posts: 1
Hello,

I've a problem with the return values of named queries:

First here's a snippet of my mapping hbm.xml file:

Code:
<class name="com.ax.dashboard.entity.CloneDiffList">
        <id name="cloneDiffListId" type="integer"/>
      <property name="activeBug" type="integer"/>
        <property name="sourceFileName" type="string" />
        <property name="sourceStartLine" type="integer" />
        <property name="sourceEndLine" type="integer" />
        <property name="sourceFragmentSize" type="integer" />
        <property name="targetFileName" type="string" />
        <property name="targetStartLine" type="integer" />
        <property name="targetEndLine" type="integer" />
        <property name="targetFragmentSize" type="integer" />
        <property name="cloneType" type="integer" />
        <property name="groupId" type="integer" />
    </class>
   
    <query name="CloneDiffList.findByFileNameAndVersion">
      <![CDATA[
         SELECT version.cloneVersionId as cloneDiffListId, 1 as activeBug, 
         version.sourceFragment.fileName.name as sourceFileName, version.sourceFragment.startLine as sourceStartLine, version.sourceFragment.endLine as sourceEndLine,
         version.sourceFragment.fragmentSize as sourceFragmentSize,
         version.targetFragment.fileName.name as targetFileName, version.targetFragment.startLine as targetStartLine, version.targetFragment.endLine as targetEndLine,
         version.targetFragment.fragmentSize as targetFragmentSize,
         version.issue.cloneType as cloneType, version.issue.group.groupId  as groupId
         
         FROM CloneVersion as version
         
         WHERE (version.sourceFragment.fileName.name = :fileName OR version.targetFragment.fileName.name = :fileName)
         AND version.startVersion.versionId <= :versionId
         AND version.endVersion.versionId >= :versionId
         
      ]]>
   </query>


The query return List<Object> instead of List<CloneDiffList>.

This is my java code to execute the query:

Code:
public List<E> findByQuery(NamedQuery namedQuery) {
        Query query = createNamedQuery(namedQuery);
        List<E> result = query.getResultList();
        return result;
    }

// NamedQuery class just wraps the query name and the parameters
protected Query createNamedQuery(NamedQuery namedQuery) {
        Query query = getEntityManager().createNamedQuery(namedQuery.getQueryName());
        if (namedQuery.getMaxResults() > 0) {
            query.setMaxResults(namedQuery.getMaxResults());
        }
        if (namedQuery.getFirstResult() > 0) {
            query.setFirstResult(namedQuery.getFirstResult());
        }

        final Map<String, Object> parameters = namedQuery.getParameterMap();
        // set parameters if exist
        Set<Entry<String, Object>> rawParameters = parameters.entrySet();
        for (Entry<String, Object> entry : rawParameters) {
            query.setParameter(entry.getKey(), entry.getValue());
        }
        return query;
    }


Thanks for help!


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

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.