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: Registering dynamic types
PostPosted: Wed Oct 24, 2007 2:38 pm 
Newbie

Joined: Mon Jun 25, 2007 3:59 pm
Posts: 15
Niberante is not capable to use dynamic type containing property added at runtime.

To reproduce, run the solution below.

Observed:

nhibernate exception

Quote:
persistent class ExtendedCustomer, ql1jodz0 not found

how to fix ?


Main program:

Code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Castle.ActiveRecord;
using System.Collections;
using Castle.ActiveRecord.Framework.Config;
using System.Reflection;
using System.CodeDom.Compiler;
using ModelEntity;

static class Program {
   static void Main() {
      try {

      Hashtable properties = new Hashtable();
      properties.Add("hibernate.connection.driver_class",
                                    "NHibernate.Driver.NpgsqlDriver");
      properties.Add("hibernate.dialect",
         "NHibernate.Dialect.PostgreSQL81Dialect");

      properties.Add("hibernate.connection.provider",
         "NHibernate.Connection.DriverConnectionProvider");

      properties.Add("hibernate.default_schema", "public");
      properties.Add("hibernate.connection.connection_string",
            "Encoding=UNICODE;Server=localhost;CommandTimeout=60;Database=eeva;User Id=admin;Password=pa");

      properties.Add("hibernate.cache.provider_class",
         "NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache");
      properties.Add("hibernate.show_sql", true);

      InPlaceConfigurationSource source = new InPlaceConfigurationSource();
      source.Add(typeof(ActiveRecordBase), properties);

      ActiveRecordStarter.Initialize(source);
      Customer.RegisterType();

      Array customers = Customer.GetFilteredList();
      Form f = new Form();
      DataGridView dgv = new DataGridView();
      dgv.Dock = DockStyle.Fill;
      f.Controls.Add(dgv);
      dgv.DataSource = customers;
         Application.Run(f);
      }
      catch (Exception e) {
         MessageBox.Show(e.ToString());
      }
   }
}

ModelEntity.dll source:

Code:
using Castle.ActiveRecord;
using System.CodeDom.Compiler;
using System;

namespace ModelEntity {
   [ActiveRecord("klient", Schema = "firma1", DynamicUpdate = true, DynamicInsert = true, Lazy = true, Cache = CacheEnum.NonStrictReadWrite)]
   public class Customer : ModelGenericBase<Customer> {

      string kood;
      [PrimaryKey("kood", Length = 12)]
      public virtual string Kood {
         get { return kood; }
         set {
            kood = value;
         }
      }
   }

   public abstract class ModelGenericBase<T> :
         ActiveRecordValidationBase<T> where T : class {

      static Type extendedType;

      public static Array GetFilteredList() {
         return FindAll(extendedType);
      }


      public static void RegisterType() {
         CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
         CompilerParameters compilerParameters = new CompilerParameters();
         compilerParameters.ReferencedAssemblies.Add("Castle.ActiveRecord.dll");
         compilerParameters.ReferencedAssemblies.Add("ModelEntity.dll");
         compilerParameters.GenerateInMemory = true;
         CompilerResults compilerResults =
                provider.CompileAssemblyFromSource(compilerParameters,
@"
using Castle.ActiveRecord;
using ModelEntity;

[ActiveRecord(""klient"", Schema = ""firma1"", DynamicUpdate = true, DynamicInsert = true, Lazy = true)]
public class ExtendedCustomer:Customer {

string name;
[Property]
public virtual string Name {
         get { return name; }
         set {
            name = value;
         }
      }
   }
");

         if (compilerResults.Errors.HasErrors) {
            string msg;
            msg = compilerResults.Errors.Count.ToString() + " Errors:";

            for (int x = 0; x < compilerResults.Errors.Count; x++)
               msg = msg + "\r\nLine: " +
                         compilerResults.Errors[x].Line.ToString() + " - " +
                         compilerResults.Errors[x].ErrorText;
            throw new ApplicationException(msg);
         }
         extendedType = compilerResults.CompiledAssembly.GetType("ExtendedCustomer");

         // inner exception:
         //{"persistent class ExtendedCustomer, ql1jodz0 not found"}
         ActiveRecordStarter.RegisterTypes(extendedType);
      }
   }
}


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.