-->
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: Use named query with different mapping from the class
PostPosted: Wed Mar 25, 2009 9:06 am 
Beginner
Beginner

Joined: Thu Aug 14, 2008 5:31 pm
Posts: 20
Hello,

I've got the following mapping for one of my classes :
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="DataTransfer.Category,DataTransfer" table="Category" lazy="true">
    <id name="CategoryID" column="CatID" type="int">
      <generator class="native" />
    </id>
    <property name="Description" type="string" column="Description" />
  </class>

  <sql-query name="sp_NH_GetCategories" callable="true">
    <return class="DataTransfer.Category, DataTransfer" >
      <return-property name="CategoryID" column="CatID" />
    </return>
    exec dbo.sp_NH_GetCategories
  </sql-query>
 
</hibernate-mapping>


As you can see the class Category has a Description property which is not returned by the stored procedure. That raises an exception when I try to execute the named query.
Of course I could just return the Description field in my stored procedure and map it, but what if I've got a class with 50 properties, I'm not going to do this for all of them ! Ideally I'd like the named query to return a Category entity with its properties set to the values return by the stored procedure, and if some fields weren't mapped, then they should be null.

Is this possible at all, if so how ?

Thanks


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.