NHibernate Forge
The official new home for the NHibernate for .NET community

Comments: Configuration and mapping

Comments (5)
History (6)

Configuration and mapping

Sort by: Published Date | Most Recent | Most Useful
By: santoshamb Posted on 10-18-2008 5:19

For anybody (like me) new to NHibernate and NHibernate.Spatial, you'll need to import

NHibernate.Spatial.Mapping

in order to build with a reference to the SpatialAuxiliaryDatabaseObject

By: patgannon Posted on 02-12-2009 0:29

The code snippet under "ActiveRecord Schema Generation Configuration" didn't work for me.  Has this code been tested with the new version of NHibernate Spatial (built with NH 2.0.1)?  When my code called Metadata.AddMapping(cfg, MetadataClass.SpatialReferenceSystem) (in the code snippet), the following exception was thrown:

NHibernate.MappingException: Resource not found: NHibernate.Spatial.Metadata.SpatialReferenceSystem.MsSql2008SpatialDialect.hbm.xml

at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)

at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)

at NHibernate.Spatial.Metadata.Metadata.AddMapping(Configuration configuration, MetadataClass clazz) in C:\Projects\NHibernate.Spatial\trunk\src\NHibernate.Spatial\src\NHibernate.Spatial\Metadata\Metadata.cs: line 63

at ... (my code)

Am I missing a mapping file for the SQL 2008 spatial dialect?  (I didn't see one in the code.)  I'm not quite sure what "SpatialReferenceSystem" is, or why I need it, so I tried commenting out that line of code (but left in the other call to AddMapping which maps MetadataClass.GeometryColumn), since the geometry column type is the only one that I really need a special mapping for.  Unfortunately, when I call ActiveRecordStarter.CreateSchema(), the following unhandled exception is thrown:

MapBehavior : FailedSystem.Data.SqlClient.SqlException: There is already an object named 'NHSP_GEOMETRY_COLUMNS' in the database.

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)

at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)

at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)

at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script, Boolean export, Boolean format, Boolean throwOnError, TextWriter exportOutput, IDbCommand statement, String sql)

at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script, Boolean export, Boolean justDrop, Boolean format, IDbConnection connection, TextWriter exportOutput)

at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script, Boolean export, Boolean justDrop, Boolean format)

NHibernate.HibernateException: There is already an object named 'NHSP_GEOMETRY_COLUMNS' in the database.

at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script, Boolean export, Boolean justDrop, Boolean format)

at NHibernate.Tool.hbm2ddl.SchemaExport.Create(Boolean script, Boolean export)

at Castle.ActiveRecord.ActiveRecordStarter.CreateSchema() in c:\Projects\Castle\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs: line 261

Castle.ActiveRecord.Framework.ActiveRecordException: Could not create the schema

at Castle.ActiveRecord.ActiveRecordStarter.CreateSchema() in c:\Projects\Castle\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs: line 265

at ...(my code)

Note that the NHSP_GEOMETRY_COLUMNS table does not exist prior to calling CreateSchema(), but it does exist after the exception is thrown.  Interestingly enough, it does actually create my table correctly with the geometry column (rather than creating that column as a 'tinyint', which was the case before I added in the aforementioned code snippet).

Any guidence you can provide would be greatly appreciated.

Thank you!

Pat Gannon

By: reddy Posted on 05-19-2009 18:01

You get this error "There is already an object named" because for some reason drop sql failed to drop an existing object and createsql is trying create that object again.

So you may want to cleanup your existing schema objects manually and try again.

RR

By: FredL Posted on 11-14-2010 14:50

For PostGis, the dialect path is:

<property name="dialect">

NHibernate.Spatial.Dialect.PostGisDialect,NHibernate.Spatial.PostGis

</property>

By: Gripenstedt Posted on 04-08-2011 11:14

Hi everyone,

I am trying to do the same thing as is described above using Fluent NHibernate and I am having some troubles getting it to work. The database is an SQL Server 2008 R2. My little sample code currently looks like this.

Property

public virtual IGeometry GeometryColumn

{

get;

set;

}

Mapping

           Table("TestTabell");

           Schema("dbo");

           Id(x => x.Id).GeneratedBy.Native();

           Not.LazyLoad();

           Map(x => x.GeometryColumn).CustomType<GeometryType>();

Configuration

           var cfg = Fluently.Configure()

              .Database(MsSqlConfiguration.MsSql2008

                            .ConnectionString(_connectionString)

                            .ProxyFactoryFactory(

                                "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle")

               //.Dialect(

               //    "NHibernate.Spatial.Dialect.MsSql2008SpatialDialect,NHibernate.Spatial.MsSql2008")

              )

              .Mappings(m => m.FluentMappings.AddFromAssemblyOf<TestTabell>());

           //.ExposeConfiguration(c => c.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(c)));

           Configuration configuration = cfg.BuildConfiguration();

           ISessionFactory sessionFactory = configuration.BuildSessionFactory();

Am I supposed to set the dialect and if so, what is the correct dialect string? Do I have to expose configuration and "AddAuxiliaryDatabaseObject"? I do not know and I would really appreciate some help.

I googled a lot and I always seem to find contradictory information regarding this.

I am thankful for any help I can get.

Powered by Community Server (Commercial Edition), by Telligent Systems