-->
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.  [ 2 posts ] 
Author Message
 Post subject: BuildSessionFactory throwing exception
PostPosted: Mon Nov 27, 2006 2:11 am 
Newbie

Joined: Mon Nov 27, 2006 2:00 am
Posts: 3
Hello,

I am trying to build a simple POCO that persists to NHibernate using Attributes. I am using Mono, Sqllite, NHibernate 1.2.0beta3 on Ubuntu.

It took me a while to figure out the NHibernate Sqlite driver doesn't use Mono, so I use this code:

Code:
namespace LightTable.Core
{
        using NHibernate.Driver;

        public class MonoDataSqliteDriver : ReflectionBasedDriver
        {
                public MonoDataSqliteDriver() : base(
                        "Mono.Data.SqliteClient",
                        "Mono.Data.SqliteClient.SqliteConnection",
                        "Mono.Data.SqliteClient.SqliteCommand")
                {
                }

                public override bool UseNamedPrefixInSql
                {
                        get { return true; }
                }

                public override bool UseNamedPrefixInParameter
                {
                        get { return true; }
                }

                public override string NamedPrefix
                {
                        get { return "@"; }
                }

                public override bool SupportsMultipleOpenReaders
                {
                        get { return false; }
                }
        }
}


My .config contains the following:

Code:
  <nhibernate>
    <add key="hibernate.dialect"
      value="NHibernate.Dialect.SQLiteDialect" />

     <add key="hibernate.connection.provider"
       value="NHibernate.Connection.DriverConnectionProvider" />

     <add key="hibernate.connection.driver_class"
       value="LightTable.Core.MonoDataSqliteDriver, LightTableCore"/>

     <add key="hibernate.connection.connection_string"
       value="URI=file:nhibernate.db,version=3" />

     <add key="hibernate.query.substitutions"
       value="true=1;false=0" />
  </nhibernate>


When I call SchemaExport, I can see my driver being instantiated and the tables being created from my annotated classes. My code looks as such:

Code:
                public static void Init()
                {
                        log4net.Config.XmlConfigurator.Configure();

                        MemoryStream stream = new MemoryStream();
                        HbmSerializer.Default.Validate = true;
                        HbmSerializer.Default.HbmDefaultAccess = "field.camelcase-underscore";
                        HbmSerializer.Default.Serialize(stream,
                                System.Reflection.Assembly.GetExecutingAssembly());
                        stream.Position = 0;
System.Console.WriteLine(new StreamReader(stream).ReadToEnd());

                        stream.Position = 0;
                        Configuration cfg = new Configuration();
                        cfg.AddInputStream(stream);
                        NHibernate.Tool.hbm2ddl.SchemaExport se = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg);
                        se.Create(true, true);

                        NHibernate.ISessionFactory sf = cfg.BuildSessionFactory();


However when I try to create a ISessionFactory, the call throws this exception:

Code:
Unhandled Exception: System.ArgumentException: Name can't be empty
Parameter name: name
  at System.Reflection.Emit.DynamicMethod..ctor (System.String name, MethodAttributes attributes, CallingConventions callingConvention, System.Type returnType, System.Type[] parameterTypes, System.Reflection.Module m, Boolean skipVisibility) [0x000ff] in /build/buildd/mono-1.1.17.1/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs:107
  at System.Reflection.Emit.DynamicMethod..ctor (System.String name, MethodAttributes attributes, CallingConventions callingConvention, System.Type returnType, System.Type[] parameterTypes, System.Type owner, Boolean skipVisibility) [0x00000] in /build/buildd/mono-1.1.17.1/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs:80
  at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Type owner, Boolean skipVisibility) [0x00000] in /build/buildd/mono-1.1.17.1/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs:77
  at NHibernate.Bytecode.Lightweight.ReflectionOptimizer.CreateDynamicMethod (System.Type returnType, System.Type[] argumentTypes) [0x00000]
  at NHibernate.Bytecode.Lightweight.ReflectionOptimizer.GenerateGetPropertyValuesMethod (NHibernate.Property.IGetter[] getters) [0x00000]
  at NHibernate.Bytecode.Lightweight.ReflectionOptimizer..ctor (System.Type mappedType, NHibernate.Property.IGetter[] getters, NHibernate.Property.ISetter[] setters) [0x00000]
  at NHibernate.Bytecode.Lightweight.BytecodeProviderImpl.GetReflectionOptimizer (System.Type mappedClass, NHibernate.Property.IGetter[] getters, NHibernate.Property.ISetter[] setters) [0x00000]
  at NHibernate.Persister.Entity.AbstractEntityPersister..ctor (NHibernate.Mapping.PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory) [0x00000]
  at NHibernate.Persister.Entity.SingleTableEntityPersister..ctor (NHibernate.Mapping.PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping) [0x00000]
  at NHibernate.Persister.PersisterFactory.CreateClassPersister (NHibernate.Mapping.PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg) [0x00000]
  at NHibernate.Impl.SessionFactoryImpl..ctor (NHibernate.Cfg.Configuration cfg, IMapping mapping, NHibernate.Cfg.Settings settings) [0x00000]
  at NHibernate.Cfg.Configuration.BuildSessionFactory () [0x00000]
  at LightTable.Core.Initialize.Init () [0x00074] in /home/george/Projects/dam/src/Core/Initialize.cs:34
  at LightTable.Core.Test.Main (System.String[] args) [0x00000] in /home/george/Projects/dam/src/Core/test.cs:7


My generated XML is fairly simple:

Code:
<?xml version="1.0" encoding="utf-8"?>
<!--Generated from NHibernate.Mapping.Attributes on 2006-11-27 01:09:29Z.-->
<hibernate-mapping default-access="field.camelcase-underscore" xmlns="urn:nhibernate-mapping-2.2">
  <class name="LightTable.Core.Media, LightTableCore" table="Media" polymorphism="implicit">
    <id name="Location">
      <generator class="assigned" />
    </id>
  </class>
</hibernate-mapping>


Is there something I am missing? I'm very new to NHibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 1:04 pm 
Newbie

Joined: Mon Nov 27, 2006 2:00 am
Posts: 3
I see the problem. Mono doesn't follow DynamicMethod.ctor semantics as .NET 2.0.

http://lists.ximian.com/pipermail/mono-bugs/2006-September/047144.html is the bug


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