-->
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: Class Not found error
PostPosted: Fri Nov 18, 2005 9:13 pm 
Hi

Im using the following creatQuery call

In the GetEmployeeByName method is in a DAO in the persistence namespace


public IList GetEmployeNames()
{
ITransaction tx = null;
try {
tx = m_session.BeginTransaction();
IQuery q = m_session.CreateQuery("SELECT new Domain.EmployeeListItem(emp.FirstName, emp.LastName) FROM Employee emp order by emp.LastName");
IList l = q.List();
tx.Commit();
return l;
}
catch (Exception ex)
{
if (tx != null) tx.Rollback();
throw ex;
}
}
EmployeeListItem is in the DOmain namespace. Domain is a project library which I have as a reference to the Persistence project

Can someone help ?


Top
  
 
 Post subject:
PostPosted: Sat Nov 19, 2005 7:06 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
You have to import any non-persistent types that you want to create using SELECT NEW (and also any enumerations that you want to us in your HQL, but that's another matter).

You can add imports in the config file (not sure how though) or programatically in your Configuration object before you create your SessionFactory.

(treat as pseudo-code)
Code:
//Create the Configuration object and add the persistent classes
Configuration cfg = new Configuration();
cfg.AddAssembly("DomainAssembly");

//This is how you import a class
System.Type typeToImport = typeof(Domain.EmployeeListItem);
cfg.CreateMappings().AddImport(typeToImport.AssemblyQualifiedName, typeToImport.FullName);


Often, I import a batch of classes in an assembly (Data Transfer Objects, for example) so I can use them in HQL.

Code:
System.Type[] typesToImport = Assembly.GetExecutingAssembly().GetTypes();

   foreach(System.Type typeToImport in typesToImport)
   {
      if(typeToImport.Namespace == "Framework.DTO")
      cfg.CreateMappings().AddImport(typeToImport.AssemblyQualifiedName, typeToImport.FullName);
   }      


Hope that helps.

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 19, 2005 11:35 pm 
thanks that worked


Top
  
 
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.