I'm having some problems with ActiveRecord.
Well everything works fine, but it's working sometimes. Not ALL the time.
When I try to navigate to MVC page that is referenced in a project that contains a spatial entity (theres just one spatial entity - and this entity does not have a spatial type) I get this exception.
{"A GeometryType column has been declared, but there is no spatial dialect configured"}
There is a dialect correctly configured. I've tried to configurate it in two ways: Xml and InPlace.
This is my startup method:
public static void StartActiveRecord()
{
IDictionary<string,string> hash = new Dictionary<string,string>();
hash.Add("isWeb", "true");
hash.Add("connection.driver_class","NHibernate.Driver.NpgsqlDriver");
hash.Add("connection.connection_string","Server=localhost;Port=5432;database=nhiber;User ID=postgres;Password=pass;");
hash.Add("connection.provider","NHibernate.Connection.DriverConnectionProvider");
hash.Add("dialect","NHibernate.Spatial.Dialect.PostGisDialect,NHibernate.Spatial.PostGis");
hash.Add("proxyfactory.factory_class","NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
InPlaceConfigurationSource source = new InPlaceConfigurationSource();
source.Add(typeof(ActiveRecordBase), hash);
ActiveRecordStarter.Initialize(source, GetActiveRecordTypes());
foreach (Configuration cfg in ActiveRecordMediator.GetSessionFactoryHolder().GetAllConfigurations())
{
cfg.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg));
//Metadata.AddMapping(cfg, MetadataClass.GeometryColumn);
//Metadata.AddMapping(cfg, MetadataClass.SpatialReferenceSystem);
}
}
And this is my Startup method, in Global.asax
protected void Application_Start()
{
Ignition.StartActiveRecord();
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
This error occurs sometimes. Killing the dev server sometimes makes it ok, but only to crash again a few steps later.
HELP!
EDIT: I'm adding the mappings to this and some other info
When there is a dialect, this errors out in Ignition.StartActiveRecord() on Global.asax. When there is no dialect it errors out in ActiveRecordStarter.Initialize();
Just to be sure, this object mapped below is the ONLY spatial aware object in the entire assembly.
public class Complaint:ActiveRecordBase<Complaint>
{
[PrimaryKey(Column="complaint_id",Generator=PrimaryKeyType.Sequence,SequenceName="complaint_seq")]
public virtual int ComplaintId { get; set; }
[Property(Column="date_of_complaint",NotNull=true)]
public virtual DateTime DateOfComplaint { get; set; }
[Property(Column="description",Length=256,NotNull=true)]
public virtual string Description { get; set; }
[Property(Column="complaint_status",NotNull=true,Default="1")]
public cityzenComplaintStatus Status { get; set; }
[BelongsTo(Column = "complaint_type_id")]
public ComplaintType Type { get; set; }
[Property("the_geom", ColumnType = "NHibernate.Spatial.Type.GeometryType, NHibernate.Spatial")]
public virtual IGeometry Geometry { get; set; }
[OneToOne(ForeignKey="official_answer_id")]
public virtual OfficialAnswer CityAnswer { get; set; }
[BelongsTo("user_id", Fetch = FetchEnum.Select, Lazy = FetchWhen.OnInvoke, Update = false, NotNull = true)]
public virtual CityzenUser User { get; set; }
[HasMany(typeof(Vote),Table="vote",ColumnKey="complaint_id",RelationType=RelationType.Set,Inverse=true)]
public virtual IList<Vote> Votes { get; set; }
[HasMany(typeof(Comment),Table="comment",ColumnKey="complaint_id",RelationType=RelationType.Set,Inverse=true)]
public virtual IList<Comment> Comments { get; set; }
[Property(Column = "deleted", Default = "false", NotNull = true)]
public virtual bool Deleted { get; set; }
}
Your configuration looks right to me but for whatever reason whenever NH instantiates an instance of GeometryType it cannot find the dialect you are configured to use so that it knows what type of IGeometry you need to initialize (PostGisGeometryType in your case).
What you may be able to do for a temporary workaround is to declare your member variable like this:
[Property("the_geom", ColumnType = "NHibernate.Spatial.Type.PostGisGeometryType, NHibernate.Spatial.PostGis")]
public virtual IGeometry Geometry { get; set; }
If I find anything else out I will post back here.