-->
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: native sql named query in mapping file
PostPosted: Wed Jun 09, 2010 2:02 pm 
Beginner
Beginner

Joined: Tue May 23, 2006 4:10 pm
Posts: 38
Location: Charleston, SC
I created an entity mapping for a helper class we use to improve performance. The entity is not mapped to a table. It's more like a DTO we return from native SQL queries. The entity mapping is shown below.

What I'm curious about are the rules with respect to using this mapping from a named sql query. In the first query shown below I have no problem returning VwNote. The second query that does not return columns for every property in the mapping gave me trouble. I could never get it working. I was not sure if Hibernate required placeholders in the query results for all mapped properties. I tried returning null and empty string in the sql query for the missing columns but always got hibernate errors (illegal named query) trying to deploy the application. Is it possible to return VwNote from a native query in a mapping file if the query results do not contain columns for every mapped property? If so, can I get a helping hand with the syntax in the mapping file. Thanks.

Grant

Code:
<hibernate-mapping>
    <class name="gov.hhs.acf.cb.nytd.models.helper.VwNote">
        <id name="noteId" type="string" />
        <property name="recordNumber" type="string"/>
        <property name="elementName" type="string"/>
        <property name="elementDescription" type="string"/>
        <property name="datumValue" type="string"/>
        <property name="noteText" type="string"/>
    </class>
</hibernate-mapping>


Code:
<sql-query name="getDatumNotes">
        <return alias="note" class="gov.hhs.acf.cb.nytd.models.helper.VwNote" />
        select
            datum_.rowid as {note.noteId},
            this_.RECORDNUMBER as {note.recordNumber},
            element_.NAME as {note.elementName},
            element_.DESCRIPTION as {note.elementDescription},
            datum_.VALUE as {note.datumValue},
            datum_.NOTES as {note.noteText}
        from TRANSMISSIONRECORD this_
            inner join TRANSMISSION trans_
                on this_.TRANSMISSIONID = trans_.TRANSMISSIONID
            inner join DATUM datum_
                on this_.TRANSMISSIONRECORDID = datum_.TRANSMISSIONRECORDID
            inner join ELEMENT element_
                on datum_.ELEMENTID = element_.ELEMENTID
        where trans_.TRANSMISSIONID = :transmissionId
            and datum_.notes is not null
        order by this_.RECORDNUMBER, element_.NAME
</sql-query>


Code:
<sql-query name="getRecordNotes">
        <return alias="note" class="gov.hhs.acf.cb.nytd.models.helper.VwNote" />
        select
            this_.rowid as {note.noteid},
            this_.RECORDNUMBER as {note.recordNumber},
            null as {note.elementName},
            null as {note.elementDescription},
            null as {note.datumValue},
            this_.NOTES as {note.noteText}
        from TRANSMISSIONRECORD this_
        where this_.NOTES is not null
            and this_.TRANSMISSIONID = :transmissionId
</sql-query>


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.