-->
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: Please help me with calling NHibernate from separate project
PostPosted: Tue May 13, 2008 3:10 pm 
Newbie

Joined: Fri May 09, 2008 5:32 pm
Posts: 1
Hello,

I don't want to skip all the important info gathering below, but I am sure I'm just missing something elemental.

I have been working with the examples project from NHibernate-2.0.0.Alpha1-src.zip and modifying for my own purposes to see how it works.

I have some unit tests set up using MbUnit within the NHibernate.Examples-2.0 project using my new tables and mappings, so I think the code and .xml files are correct. Data inserts, updates, etc all work as i would expect them to.

Now, when I tried to move my test fixtures from within the NHibernate.Examples-2.0 project into a new test project, I am receiving an error on trying to run my unit tests in a new project which references the examples project.

Hibernate version:
2.0.0

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

   <class name="NHibernate.Examples.QuickStart.Giftcard, NHibernate.Examples" table="giftcard"
         lazy="false">
      <id name="Id" unsaved-value="0">
         <generator class="native" />
      </id>
      <property name="Name"/>
      <property name="Message"/>
      <property name="Number"/>
      <property name="SecurityCode" column="security_code"/>
      <property name="Salt"/>
      <property name="StatusId" column="status_id"/>
      <property name="InitialAmount" column="initial_amount"/>
      <property name="Balance"/>
      <property name="AmountCommitted" column="amount_committed"/>
      <property name="AvailableBalance" column="available_balance"/>
      <property name="BuyerAddressId" column="buyer_address_id"/>
      <property name="RecipientAddressId" column="recipient_address_id"/>
      <property name="DateCreated" column="date_created" not-null="true" insert="false" update="false"/>
   </class>

</hibernate-mapping>


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

code in new test project which calls the object method in the DAL project:
Code:
[TestFixture]
public class GiftCardFixture
{
    [Test, RollBack]
    public void GiftcardAdd()
    {
        Giftcard newGiftcard = new Giftcard();
        newGiftcard.Name = "test card";
        newGiftcard.Message = "test message";
        newGiftcard.Number = "1234567890123456";
        newGiftcard.SecurityCode = "123456";
        newGiftcard.Salt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        newGiftcard.StatusId = 1;
        newGiftcard.InitialAmount = 500;
        newGiftcard.Balance = 500;
        newGiftcard.BuyerAddressId = 1;
        newGiftcard.RecipientAddressId = 1;
        newGiftcard.AmountCommitted = 0;

        int generatedId = newGiftcard.Add();

        Assert.IsTrue(generatedId > 0);

    }
}


code in the DAL project which handles the call from above:
Code:
public int Add()
        {
            Configuration cfg = new Configuration();
            cfg.AddAssembly("NHibernate.Examples");

            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            ITransaction transaction = session.BeginTransaction();

            // Tell NHibernate that this object should be saved
            int generatedId = (int)session.Save(this);

            // commit all of the changes to the DB and close the ISession
            transaction.Commit();
            session.Close();

            return generatedId;
           
        }


it is choking on the

Code:
cfg.AddAssembly("NHibernate.Examples");


line.

Full stack trace of any exception that occurs:
Code:
Message: Could not compile the mapping document: NHibernate.Examples.GiftCardTransaction.GiftcardTransaction.hbm.xml

Type: NHibernate.MappingException
Source: NHibernate
TargetSite: Void LogAndThrow(System.Exception)
HelpLink: null
Stack:   at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
   at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
   at NHibernate.Cfg.Configuration.ProcessMappingsQueue()
   at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document)
   at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name)
   at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
   at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
   at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
   at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
   at NHibernate.Examples.QuickStart.Giftcard.Add() in C:\Documents and Settings\mcomroe\My Documents\Visual Studio 2005\Projects\GiftCardDAL\GiftCardDAL\GiftCard\Giftcard.cs:line 119
   at eDevix.GiftCardDALTests.GiftCardFixture.GiftcardAdd() in C:\Documents and Settings\mcomroe\My Documents\Visual Studio 2005\Projects\GiftCardDAL\GiftCardDALTests\GiftCardfixture.cs:line 27


The only references in the test project are to MbUnit.Framework and a project reference to the DAL project so I can get at those objects.

I guess the important thing to keep in mind is that my tests run fine when they are within the DAL project, and just not when they are in the separate test project.

I'm sure the problem is between the user and keyboard, but any help would be greatly appreciated.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 6:40 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
For me it looks as the XML file does not pass XML validation - check the file whether there are some illegal characters. Is the empty line legal after <?xml> element?

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 15, 2008 3:02 am 
Regular
Regular

Joined: Thu Mar 06, 2008 5:06 am
Posts: 68
I'm not sure, but perhaps the id with the name "Id" is the reason. "id" is a reserved word in NHibernate. Could you rename the key property and try it again?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 15, 2008 3:35 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Is there an inner exception with a more meaningful error ?

_________________
--Wolfgang


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.