-->
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.  [ 3 posts ] 
Author Message
 Post subject: Load a collection of a class with stored procedures
PostPosted: Fri Jun 08, 2007 5:34 am 
Newbie

Joined: Mon Apr 23, 2007 3:55 pm
Posts: 10
This might be a newbie question, but I need to load a collection of Users.

Let's say the query in the stored procedures is like this;
Code:
SELECT Username FROM Users WHERE Email = @Email


From my Users.hbm.xml file:
Code:
<sql-query name="SelectUsersByEmail">
        <return alias="Users" class="SimpleUser" />
        exec SelectUsersByEmail :Email
    </sql-query>


Now I understand very well why this doesn't work, but can I load a collection of users without having to create some kind of lame custom collection. I just want to use a List.

Thanks!


Top
 Profile  
 
 Post subject: Proc to load collection
PostPosted: Fri Jun 08, 2007 2:46 pm 
Beginner
Beginner

Joined: Fri Jul 14, 2006 1:51 pm
Posts: 27
Here's a mapping I have that loads comments for a blog post using a stored procedure.

Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
      assembly="NHBlog.Domain" namespace="NHBlog.Domain">
  <class name="BlogPost" table="BlogPost">
    <id name="ID" column="ID" type="int">
      <generator class="native" />
    </id>
    <property name="Title" column="Title" type="string" not-null="true"></property>
    <property name="Body" column="Body" type="string" not-null="true"></property>
    <property name="PublishedOn" column="PublishedOn" type="DateTime"></property>
    <many-to-one name="PublishedBy" column="PublishedByID" class="BlogUser" not-null="true" />
    <bag name="Comments" cascade="delete" inverse="true" >
      <key column="BlogPostID" />
      <one-to-many class="Comment" />
      <loader query-ref="GetCommentsByBlogPostID"/>
    </bag>
  </class>
  <sql-query name="GetCommentsByBlogPostID">
    <load-collection alias="Comments" role="BlogPost.Comments" />
    exec GetCommentsByBlogPostID :blogPostID
  </sql-query>
</hibernate-mapping>


In my BlogPost class I have an IList<Comment> property. Is this the functionality you are looking for?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 11, 2007 4:12 am 
Newbie

Joined: Mon Apr 23, 2007 3:55 pm
Posts: 10
Thanks for your reply!
No, that's not what I',m looking for. Let's say in your case that you want a list of blogs, depending on the name. Which means, you'll need a collection of blogs somewhere. How would you solve this?


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

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.