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.  [ 1 post ] 
Author Message
 Post subject: mapping.attributes still demands hbm.xml
PostPosted: Wed Apr 23, 2008 7:55 am 
Newbie

Joined: Wed Apr 23, 2008 7:04 am
Posts: 1
I'm trying to achieve simple mapping using mapping.attributes. Somehow, it doesn't work. My Decorated Class is in the same namespace as the program, configuration is done via xml-file.

Although i use the Mappings.Attributes, I always get a "resource not found
QuickStart.User.hbm.xml" Exception.

Here's all I have done so far:

Code:
/*program.cs*/
namespace QuickStart
{
    class Program
    {
        static void Main(string[] args)
        {

            try
            {
              NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
                NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true;
                cfg.AddInputStream( NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(                                                System.Reflection.Assembly.GetExecutingAssembly()
                                            )
                                   );
                cfg.AddClass(typeof(User));
                cfg.Configure("C:\\path\\nhibernate.config");
                ISessionFactory sf = cfg.BuildSessionFactory();

                ISession ses = sf.OpenSession();
                ITransaction ta = ses.BeginTransaction();             

                ses.Close();               
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.Message);
            }
        }
    }
}


Code:
<!--xmlconfig-->
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
    <property name="connection.connection_string">Data Source=srv.foo.de; User Id=usrid; Password=pwd; Persist Security Info=True;</property>
    <property name="connection.isolation">ReadCommitted</property>
    <property name="query.substitutions">True=1;False=0</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

Code:
/*mapped filed*/
namespace QuickStart
{
    [NHibernate.Mapping.Attributes.Class(0,
                                             Table = "users",
                                             Schema = "schema")]
    public class User
    {
        [NHibernate.Mapping.Attributes.Id(0,
                                         Column = "logonid",
                                         Name = "logonId",
                                         TypeType = typeof(string),
                                         UnsavedValue = "")]
        public string logonId;

        [NHibernate.Mapping.Attributes.Property(0,
                                          Column = "name",
                                          Name = "Name",
                                          TypeType = typeof(string),
                                          NotNull = true,
                                          Length = 100)]
        public string name;

    }
}

Full stack trace of any exception that occurs:
bei NHibernate.Cfg.Configuration.LogAndThrow(MappingException me)
bei NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
bei NHibernate.Cfg.Configuration.AddClass(Type persistentClass)
bei QuickStart.Program.Main(String[] args) in C:\path\HibernateTest\Program.cs:Zeile 27.

Name and version of the database you are using:
oracle10g

Can anyone help me on this?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.