-->
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.  [ 5 posts ] 
Author Message
 Post subject: Unknown entity class - yes, I have embedded resources
PostPosted: Tue Dec 20, 2005 12:41 pm 
Newbie

Joined: Tue Nov 01, 2005 6:32 pm
Posts: 16
Project.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="Advisor.Project, Advisor" table="project">
   
      <id name="Id" column="project_id" unsaved-value="0">
         <generator class="assigned"/>
      </id>
      <property name="Name" column="Project_Name" type="String"/>
      
      ....

   </class>
</hibernate-mapping>


log
Code:
2005-12-20 11:14:36,238 [6080] INFO  NHibernate.Cfg.Configuration - searching for mapped documents in assembly: Advisor.Mappings
...
2005-12-20 11:14:37,297 [6080] INFO  NHibernate.Cfg.Configuration - Found mapping documents in assembly: Project.hbm.xml
2005-12-20 11:14:37,297 [6080] INFO  NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2000Dialect
2005-12-20 11:14:37,313 [6080] INFO  NHibernate.Cfg.Binder - Mapping class: Advisor.Project -> project
2005-12-20 11:14:37,313 [6080] DEBUG NHibernate.Cfg.Binder - Mapped property: Id -> project_id, type: Int32
2005-12-20 11:14:37,328 [6080] DEBUG NHibernate.Cfg.Binder - Mapped property: Name -> Project_Name, type: String
2005-12-20 11:14:37,328 [6080] DEBUG NHibernate.Cfg.Binder - Mapped property: IsIndirect, type: Boolean
2005-12-20 11:14:37,328 [6080] DEBUG NHibernate.Cfg.Binder - Mapped property: ParentCustomer -> customer_id, type: Customer
....
2005-12-20 11:14:37,391 [6080] DEBUG Advisor.Labels.DataLayerNH - Completed adding assembly [Advisor.Mappings] to configuration
2005-12-20 11:14:37,453 [6080] INFO  NHibernate.Cfg.Configuration - processing one-to-many association mappings
....
2005-12-20 11:14:37,484 [6080] DEBUG NHibernate.Cfg.Binder - Second pass for collection: Advisor.Project.SalesOrders
2005-12-20 11:14:37,484 [6080] INFO  NHibernate.Cfg.Binder - mapping collection: Advisor.Project.SalesOrders -> sales_order
2005-12-20 11:14:37,484 [6080] DEBUG NHibernate.Cfg.Binder - Mapped collection key: project_id, one-to-many: SalesOrder
...
2005-12-20 11:14:37,546 [6080] INFO  NHibernate.Cfg.Configuration - processing one-to-one association property references
2005-12-20 11:14:37,546 [6080] INFO  NHibernate.Cfg.Configuration - processing foreign key constraints
....
2005-12-20 11:14:37,546 [6080] DEBUG NHibernate.Cfg.Configuration - resolving reference to class: Project
2005-12-20 11:14:37,640 [6080] INFO  NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2000Dialect
2005-12-20 11:14:37,640 [6080] INFO  NHibernate.Cfg.SettingsFactory - use outer join fetching: True
2005-12-20 11:14:37,640 [6080] INFO  NHibernate.Connection.ConnectionProviderFactory - Intitializing connection provider: NHibernate.Connection.DriverConnectionProvider
2005-12-20 11:14:37,640 [6080] INFO  NHibernate.Connection.ConnectionProvider - Configuring ConnectionProvider
2005-12-20 11:14:37,640 [6080] INFO  NHibernate.Cfg.SettingsFactory - Optimize cache for minimal puts: False
2005-12-20 11:14:37,640 [6080] INFO  NHibernate.Cfg.SettingsFactory - Query language substitutions: {}
2005-12-20 11:14:37,640 [6080] INFO  NHibernate.Cfg.SettingsFactory - cache provider: NHibernate.Cache.HashtableCacheProvider
2005-12-20 11:14:37,640 [6080] INFO  NHibernate.Cfg.SettingsFactory - Using Isolation Level: ReadCommitted
2005-12-20 11:14:37,655 [6080] INFO  NHibernate.Cfg.Configuration - instantiating and configuring caches
2005-12-20 11:14:37,671 [6080] INFO  NHibernate.Impl.SessionFactoryImpl - building session factory
2005-12-20 11:14:37,671 [6080] DEBUG NHibernate.Impl.SessionFactoryImpl - instantiating session factory with properties: {hibernate.dialect=NHibernate.Dialect.MsSql2000Dialect, hibernate.connection.isolation=ReadCommitted, hibernate.connection.connection_string=Server=prod-sql-01;Initial Catalog=advisor_dev;Integrated Security=SSPI, hibernate.connection.provider=NHibernate.Connection.DriverConnectionProvider, hibernate.connection.driver_class=NHibernate.Driver.SqlClientDriver}
2005-12-20 11:14:37,749 [6080] DEBUG NHibernate.SqlCommand.SqlSelectBuilder - The initial capacity was set too low at: 8 for the SelectSqlBuilder that needed a capacity of: 10 for the table label_audit audits0_
2005-12-20 11:14:37,764 [6080] DEBUG NHibernate.SqlCommand.SqlSelectBuilder - The initial capacity was set too low at: 14 for the SelectSqlBuilder that needed a capacity of: 24 for the table project projects0_
2005-12-20 11:14:37,796 [6080] DEBUG NHibernate.SqlCommand.SqlSelectBuilder - The initial capacity was set too low at: 8 for the SelectSqlBuilder that needed a capacity of: 10 for the table sales_order salesorder0_
2005-12-20 11:14:37,796 [6080] DEBUG NHibernate.SqlCommand.SqlSelectBuilder - The initial capacity was set too low at: 10 for the SelectSqlBuilder that needed a capacity of: 14 for the table label_permission_set_indiv labelpermi0_ inner join label_permission_set [labelpermi0__1_] on labelpermi0_.permission_id=[labelpermi0__1_].permission_id
2005-12-20 11:14:37,796 [6080] DEBUG NHibernate.SqlCommand.SqlSelectBuilder - The initial capacity was set too low at: 8 for the SelectSqlBuilder that needed a capacity of: 10 for the table customer_business_unit businessun0_
2005-12-20 11:14:37,796 [6080] DEBUG NHibernate.SqlCommand.SqlSelectBuilder - The initial capacity was set too low at: 10 for the SelectSqlBuilder that needed a capacity of: 12 for the table project projects0_
2005-12-20 11:14:37,796 [6080] DEBUG NHibernate.SqlCommand.SqlSelectBuilder - The initial capacity was set too low at: 10 for the SelectSqlBuilder that needed a capacity of: 14 for the table group_member securitygr0_
2005-12-20 11:14:37,827 [6080] DEBUG NHibernate.SqlCommand.SqlSelectBuilder - The initial capacity was set too low at: 8 for the SelectSqlBuilder that needed a capacity of: 12 for the table employee_active employee0_
2005-12-20 11:14:37,842 [6080] DEBUG NHibernate.SqlCommand.SqlSelectBuilder - The initial capacity was set too low at: 8 for the SelectSqlBuilder that needed a capacity of: 16 for the table customer_business_unit customerbu0_
2005-12-20 11:14:37,858 [6080] DEBUG NHibernate.Impl.SessionFactoryObjectFactory - initializing class SessionFactoryObjectFactory
2005-12-20 11:14:37,858 [6080] DEBUG NHibernate.Impl.SessionFactoryObjectFactory - registered: 54418a224dce42d58b2d5b8d3ca673f2(unnamed)
2005-12-20 11:14:37,858 [6080] INFO  NHibernate.Impl.SessionFactoryObjectFactory - no name configured
2005-12-20 11:14:37,858 [6080] DEBUG NHibernate.Impl.SessionFactoryImpl - Instantiated session factory


exception
Code:
NHibernate.MappingException: Unknown entity class: Advisor.Project


The assembly (Advisor.Mappings) has Project.hbm.xml in it. Viewing the assembly in Reflector, I can see that Visual Studio is changing the name of the embedded resource to Advisor.Mappings.Project.hbm.xml. Could this be a problem?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 12:57 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Quote:
Code:
2005-12-20 11:14:37,313 [6080] INFO  NHibernate.Cfg.Binder - Mapping class: Advisor.Project -> project


As you see, the project class is found and mapped, so the problem must be elsewhere. Please post the code that is throwing the exception.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 2:17 pm 
Newbie

Joined: Tue Nov 01, 2005 6:32 pm
Posts: 16
sergey wrote:
As you see, the project class is found and mapped, so the problem must be elsewhere.


which is why I was confused and wanted to get rid of the "embedded resource" idea immediately :)

Here's the code:

Code:
public Project LoadProject(int projectId)
{
   ISession session = GetSession();

   Project p = (Project) session.Load(typeof(Project), projectId);
   
   return p;
}


/// <summary>
/// Returns an ISession object to the caller (the session will either be the current session or a new session, depending on when it is called).
/// This method handles determining whether a new session needs to be opened internally.
/// </summary>
/// <returns>An ISession for use in this class</returns>
private static ISession GetSession()
{
   //test if we are running within ASP.NET
   if (HttpContext.Current == null)
   {
      //if we are not, we want to have a session that is static to this application domain
      if (log.IsDebugEnabled) log.Debug("GetSession - using appdomain static session");
      
      if (m_session == null)
      {
         m_session = CreateSession();
      }
      if (log.IsDebugEnabled) log.Debug("GetSession - returning session to caller");
      return m_session;
   }
   else
   {
      //we are running inside of ASP.NET
      //we want to make the session static to the http request
      if (log.IsDebugEnabled) log.Debug("GetSession - using http request static session");

      HttpContext currentContext = HttpContext.Current;

      ISession session = currentContext.Items[HTTP_SESSION_KEY] as ISession;

      if (session == null)
      {
         session = CreateSession();
         currentContext.Items[HTTP_SESSION_KEY] = session;
      }

      return session;
   }
}

/// <summary>
/// Does the actual instantiating of a new session
/// </summary>
/// <returns>A newly opened ISession</returns>
private static ISession CreateSession()
{
   if (log.IsInfoEnabled) log.Info("Instantiating new ISession from factory");
   return nhFactory.OpenSession();
}

static ISessionFactory nhFactory = initializeFactory();

/// <summary>
/// Initializes the ISessionFactory.
/// </summary>
/// <returns>ISessionFactory for this class. Note the use of this method in the declaration of the static nhFactory member.</returns>
static ISessionFactory  initializeFactory()
{
   if (log.IsDebugEnabled) log.Debug("initializeFactory() starting, about to construct Configuration");

   Configuration nhConfig = new Configuration();
   if (log.IsDebugEnabled) log.Debug("Created new NH configuration object");

   nhConfig.AddAssembly( ConfigHandler.HbmAssemblyName );
   if (log.IsDebugEnabled) log.DebugFormat("Completed adding assembly [{0}] to configuration", ConfigHandler.HbmAssemblyName);

   nhFactory = nhConfig.BuildSessionFactory();

   if (log.IsDebugEnabled) log.Debug("Constructed ISessionFactory, returning");

   return nhFactory;
}


Strangely everything was working OK until I started to move this code into another project.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 2:20 pm 
Newbie

Joined: Tue Nov 01, 2005 6:32 pm
Posts: 16
Is there any way to get access to / log the collection of class persisters at runtime?

edit: In the VS debugger, I can see that my nhFactory has 12 classPersisters, and all of the type names match what I expect to see.

However, if I set a breakpoint inside my LoadProject method, and take a look at the session object's factory property, I see that it has 12 keys in the classPersister collection as well, although the debugger seems unable to peek inside most of the session's attribtes (error: cannot obtain value)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 2:59 pm 
Newbie

Joined: Tue Nov 01, 2005 6:32 pm
Posts: 16
oh god

I changed the name of my main library/Domain Model assembly, but there happened to be an old copy with the old name in the unit test's bin folder anyway.

So the code was compiled referenced against (class) Advisor.Project (assembly) Advisor.Library, but the HBM referenced "Advisor.Project, Advisor".



D'oh! :D


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