-->
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.  [ 4 posts ] 
Author Message
 Post subject: Get values from multiple tables
PostPosted: Thu Feb 15, 2007 3:25 pm 
Newbie

Joined: Thu Feb 15, 2007 12:48 pm
Posts: 11
Hi,
I need to get values from multiple tables into a Custom data structure.
Example:
Table 1: ID, Name
Table 2: ID, Location
Table3: ID, Brand

My class looks like:
Code:
public class Data
{
   private IList locations;
   private IList names;
   private IList brand;

   public IList Location
   {
       set { locations = value; }
       get { return locations; }
   }

   public IList Name
   {
       set { names= value; }
       get { return names; }
   }

   public IList Brand
   {
       set { brand= value; }
       get { return brand; }
   }
}


The class Data does not belong to any table. It is just a Data class that I would like to use in my application.
Can I achieve this functionality using NHibernate? If so, can someone give me an example mapping file?

Thanks,
Javid
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 4:17 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
NHibernate works with entities. So if you dont have actual domain entities to work with then you'll be better off using ado.net directly.

If you have domain entities that contain relationships to the type of data you are talking about you can place values from entities into custom data structures with the import statement and a query:

Import:
Code:
<import class="RemoteNet.Model.IDValueItem, RemoteNet.Model, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8015180c1ac00233" rename="IDValueItem" />


Query:
Code:
select new IDValueItem(dept.Id, dept.Name) from Department as dept


With the import strategy you will neeed exsiting entities though.


Top
 Profile  
 
 Post subject: Re: Get values from multiple tables
PostPosted: Thu Feb 15, 2007 4:57 pm 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
javid wrote:
The class Data does not belong to any table. It is just a Data class that I would like to use in my application.
Can I achieve this functionality using NHibernate? If so, can someone give me an example mapping file?

Thanks,
Javid


Are the Names, Locations and Brands stored in the database? Are they being handled by NHibernate?

If so, then in sounds like you just want to have a lookup list that you hold on to and can use whenver you need it. Is that right?

From my experience, this sounds like a bad idea. I'm no expert on sessions, but it seems like you could get into session issues by loading those lists early and leaving them around. You would need to either leave the session open, or you would need to reconnect them? (Maybe someone can comment on the accuracy of this statement?)

Anyways, in my WinForms application, when I need to provide a list of choices, I populate an IList in the form itself. The form has its own session. When I'm done with the form, the IList goes away, too.

You can fill the IList with HQL. That is what I do. Here's a basic example of an HQL search;

Code:

IList<MyObjectClass> _list =
  SearchByHQL(_session, "from MyBusinessObject as b where b.IsActive = 'Y'");

public static IList<T> SearchByHQL(ISession session, string hql)
{
  IQuery q = session.CreateQuery(hql);
  return q.List<T>();
}



Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 6:27 pm 
Newbie

Joined: Thu Feb 15, 2007 12:48 pm
Posts: 11
Thanks Pelton:
I understand what you meant.

Javid


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.