Feel like a geek and get yourself Ema Personal Wiki for Android and Windows

30 March 2010

NHibernate: SQL query error

A unittest failed with this exception from the MSSQL CE provider:
System.Data.SqlServerCe.SqlCeException: There was an error parsing the query. 
[ Token line number = 1,Token line offset = 34,Token in error = ) ].
The SQL statements are generated by NHibernate, so this was a litte bit confusing. 

Fortunately, there is logging. And an excellent viewer.

The generated SQL statement does not contain any values to INSERT. This is logically correct, because the entity class does not contain persistent properties itself: it only contains two mapped collections:
public class HL7v3InfoMap : ClassMap<HL7v3Info>
{
    public HL7v3InfoMap()
    {
        Id(x => x.Id);

        HasManyToMany(x => x.FunctioneleEenheden)
            .Access.CamelCaseField()
            .Cascade.All();

        HasManyToMany(x => x.DataTypen)
            .Access.CamelCaseField()
            .Cascade.All();
    }
}
In this case the mapping was not finished yet, so the problem solved itself when I added more properties. But I also have cases where the class does not have any persistent properties of itself, for example a class that is an abstract base class.

I don't know a better solution than adding a dummy property to the entity.

No comments: