views:

34

answers:

1

I'm new to NHibernate, so this is probably my mistake, but when I use:

schema.Create(true, true);

I get:

SchemaExport [(null)]- There is already an object named 'XXX' in the database.
System.Data.SqlClient.SqlException: There is already an object 
named 'XXX' in the database.

I grabbed the SQL code nHibernate was using, ran it directly from MSSMS, and recieved similar errors. Looking into it, the generated code is not properly dropping the foreign key constraints. The drop looks like this:

if exists (select 1 from sysobjects where id = OBJECT_ID(N'dbo[FK22212EAFBFE4C58]')
AND parent_obj = OBJECT_ID('YYY'))
alter table dbo.YYY  drop constraint FK22212EAFBFE4C58

Doing a "select OBJECT_ID(N'dbo[FK22212EAFBFE4C58]')" I get null. If I take out the "dbo" (i.e. "select OBJECT_ID(N'[FK22212EAFBFE4C58]')") then the ID is returned.

So, my question is, why is nHibernate adding the dbo, and why does that prevent the object from being returned (since the table owning the constraint is dbo.XXX)

One of my mapping files:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="CanineApp.Model" assembly="CanineApp.Model" xmlns="urn:nhibernate-mapping-2.2">
  <class name="MedicalLog" table="MedicalLog" schema="dbo">
    <id name="MedicalLogID" type="Int64">
      <generator class="identity" />
    </id>
    <property name="InvoiceAmount" type="Decimal" not-null="true" />
    ...
    <many-to-one name="Canine" class="Canine" column="CanineID" not-null="true" fetch="join" />
    <many-to-one name="TreatmentCategory" class="TreatmentCategory" column="TreatmentCategoryID" not-null="true" access="field.camelcase-underscore" />
  </class>
</hibernate-mapping>
A: 

Answer: . It's probably a bug. There was an entry for this exact issue for SQL Server 2005. It doesn't appear to have been flagged for SQL 2000, so I'll either create a bug report or fix it.

Kendrick