-->
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.  [ 9 posts ] 
Author Message
 Post subject: Can't test database connection
PostPosted: Wed Jul 29, 2009 7:09 am 
Newbie

Joined: Tue Jul 28, 2009 8:28 am
Posts: 18
Hi, I'm trying to connect to an oracle database, and am using the following code to try and return a result to test my connection. However this just returns a null application and I've no idea why. When I step through the code, m_session is created successfully and my connection string is correct. I've no idea where to go next, any help would be appreciated.

Code:
m_session = m_sessionFactory.OpenSession();
try
{
       ICriteria criteria = m_session.CreateCriteria(typeof(PlanApplication));
       criteria.Add(Restrictions.Eq("ApplicationNumber", "2009/00011/PA"));
       PlanApplication application = (PlanApplication)criteria.UniqueResult();
}


Top
 Profile  
 
 Post subject: Re: Can't test database connection
PostPosted: Thu Jul 30, 2009 1:47 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
With criterias this normally happens when hibernate doesn't know the class. How do you add your mapping files ? If you use cfg.AddAssembly(..) check if the mapping file has Build Action=Embedded Ressource.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Can't test database connection
PostPosted: Thu Jul 30, 2009 4:33 am 
Newbie

Joined: Tue Jul 28, 2009 8:28 am
Posts: 18
I created my mapping file manually by copying parts out of a working project in VS 2005 .Net 2.0. This is my mapping file (I've only mapped 4 fields at the start to get it and working first):

JobApplication.hbm.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="MyProject.BusinessEntities" namespace="MyProject.BusinessEntities">
  <class name="JobApplication" table="JOB_APPLICATION" dynamic-update="true" >
    <id name="RefNo" column="REFERENCE">
    </id>
    <property name="StaffNumber" column="STAFF_NUMBER" type="AnsiString"/>
    <property name="ApplicationType" column="APPLICATION_TYPE" type="AnsiString"/>
    <property name="Address" column="ADDRESS" type="AnsiString"/>
  </class>
</hibernate-mapping>


Then this is my class file for returning data from the mapping:

JobApplication.cs

Code:
namespace MyProject.BusinessEntities
{
    public class JobApplication
    {
        private string m_refNo;

        public virtual string RefNo
        {
            get { return m_refNo; }
            set { m_refNo = value; }
        }

        private string m_staffNumber;

        public virtual string StaffNumber
        {
            get { return m_staffNumber; }
            set { m_staffNumber = value; }
        }

        private string m_applicationType;

        public virtual string ApplicationType
        {
            get { return m_applicationType; }
            set { m_applicationType = value; }
        }

        private string m_address;

        public virtual string Address
        {
            get { return m_address; }
            set { m_address = value; }
        }

    }
}


Top
 Profile  
 
 Post subject: Re: Can't test database connection
PostPosted: Thu Jul 30, 2009 4:37 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you post the code where you build the session factory ? And the configuration file ? You must have something like that somewhere in your code:

Configuration cfg = new Configuration()
.AddFile("Item.hbm.xml")
.AddFile("Bid.hbm.xml");

or

Configuration cfg = new Configuration()
.AddClass(typeof(NHibernate.Auction.Item))
.AddClass(typeof(NHibernate.Auction.Bid));

or

Configuration cfg = new Configuration()
.AddAssembly( "NHibernate.Auction" );

In the last case, you have to mark all hbm.xml files as "Embedded Resource".

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Can't test database connection
PostPosted: Thu Jul 30, 2009 5:06 am 
Newbie

Joined: Tue Jul 28, 2009 8:28 am
Posts: 18
Yeh here is the following code under the BusinessLogic project:

Code:
namespace MyProject.BusinessLogic
{
    public class DataManager : IDisposable
    {
        #region Default stuff

        #region Variables

        public ISession m_session;
        public ISessionFactory m_sessionFactory;

        #endregion

        #region Constructors

        /// <summary>
        /// Default constructor, configures and opens an Nhibernate session
        /// </summary>
        public DataManager()
        {
            Configuration config = new Configuration().Configure();
            m_sessionFactory = config.BuildSessionFactory();
        }

        public DataManager(ISessionFactory sessionFactory)
        {
            m_sessionFactory = sessionFactory;
        }

        #endregion

        #region IDisposable

        /// <summary>
        /// If a hibernate session exists it is closed
        /// </summary>
        public void Dispose()
        {
            if (m_session != null)
            {
                if (m_session.IsOpen)
                {
                    m_session.Close();
                }
            }
        }

        #endregion

        #endregion

        #region Test code

        public JobApplication FetchJobApplication(string referenceNumber)
        {
                m_session = m_sessionFactory.OpenSession();
                try
                {
                   ......
                }
         }
   }
}


Top
 Profile  
 
 Post subject: Re: Can't test database connection
PostPosted: Thu Jul 30, 2009 5:30 am 
Newbie

Joined: Tue Jul 28, 2009 8:28 am
Posts: 18
Where abouts in the following mapping file would I therefore put Build Action=Embedded Resource ?

Code:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="MyProject.BusinessEntities" namespace="MyProject.BusinessEntities">
  <class name="JobApplication" table="JOB_APPLICATION" dynamic-update="true" >
    <id name="RefNo" column="REFERENCE">
    </id>
    <property name="StaffNumber" column="STAFF_NUMBER" type="AnsiString"/>
    <property name="ApplicationType" column="APPLICATION_TYPE" type="AnsiString"/>
    <property name="Address" column="ADDRESS" type="AnsiString"/>
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Can't test database connection
PostPosted: Thu Jul 30, 2009 5:34 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I can't see anything that implies that your mappings are registered in the session factory. Maybe they are added in the config file ? If not then the error is clear ... read this part of the docs:

http://nhforge.org/doc/nh/en/index.html#session-configuration

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Can't test database connection
PostPosted: Thu Jul 30, 2009 6:00 am 
Newbie

Joined: Tue Jul 28, 2009 8:28 am
Posts: 18
Hi wolli, thanks for the help but I'm now getting further problems. I'm getting the following exception:

TestProject.MyProject.FetchApplicationByReference : NHibernate.MappingException : Could not compile the mapping document: MyProject.BusinessEntities.JobApplication.hbm.xml
----> NHibernate.HibernateException : Could not instantiate dialect class NHibernate.Dialect.OracleDialect
----> System.TypeLoadException : Could not load type NHibernate.Dialect.OracleDialect. Possible cause: no assembly name specified.

My hibernate.cfg.xml is as follows:

Code:
<?xml version="1.0" encoding="utf-8" ?>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="dialect">NHibernate.Dialect.OracleDialect</property>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="connection.connection_string">Data Source=JOBDB; User ID=***; Password=***</property>
      <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
      <property name="show_sql">true</property>
      <property name="max_fetch_depth">3</property>
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
      <mapping assembly="MyProject.BusinessEntities" />
    </session-factory>
  </hibernate-configuration>


Does any of this look wrong based on my source code above above? My mapping file is set to embedded resource and to instantiate the Configuration I've used the following lines:

Code:
Configuration config = new Configuration().Configure().AddAssembly("MyProject.BusinessEntities");
m_sessionFactory = config.BuildSessionFactory();


Top
 Profile  
 
 Post subject: Re: Can't test database connection
PostPosted: Thu Jul 30, 2009 6:43 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
http://www.mail-archive.com/castle-project-users@googlegroups.com/msg03171.html

_________________
--Wolfgang


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