views:

24

answers:

1

Hi everyone. I have a problem with NHibernate and the postgresql POINT data type (although I believe this is a common problem for all of those trying to map a SQL TYPE that is not covered by NHibernate SqlTypes).

My Data.Point class has two public floats: xcoordinate and ycoordinate.

My first attempt was trying to implement the IUserType interface, but I soon found out that the problem comes earlier, during the mapping phase:

MappingException was unhandled by user code:
Could not determine type for: Data.PointUserType,Data.Point, for columns: NHibernate.Mapping.Column(coordinates)

I'm very new to NHibernate, but it seems to me that I can only create a new type if the column in the database is of a known type (one of float, int, varchar and all "classic" types, but not the geometric ones I need).

I had managed to map my POINT to two different properties, by mapping to coordinates[0] and coordinates[1]. But this is only useful for SELECT and UPDATE queries, as for INSERT postgresql will complain that "coordinates" is not nullable.

Also, I can't find an actual version of NHibernate Spatial extensions, and I'd much rather have control of my POINT type, since I'll be using this type very seldom, and thus I would rather not load the entire NHibernate Spatial assemblies (supposing they are actively developed, otherwise I'll keep away from them anyways).

My final thoughts are that I would need to mess with NHibernate's SQL Generation (since some part of the insertion SQL would be '(a, b)'::point, something very specific), and maybe that's a little too troublesome (maybe not, I'd be willing to check it out).

I'm fairly new to NHibernate, but I'm getting desperate. Can anyone point me somewhere?

A: 

I recently got nHibernate working with SQL Server 2008. To see how see this question: NHibernate.Spatial and Sql 2008 Geography type - How to configure

It would be easier to help if you included you mapping file. I'm wondering if you have correctly registered your IUserType? It should look something like this

<class name="WhereAmI">
    <property name="Point">
        <type name="MyProject.MyPointUserType, MyProject">
        </type>
    </property>
</class>

Also consider taking a look at the following IUserType implementation which works for MS SQL Servier 2008: NHibernate.Spatial.Type.GeometryType

Iain