I'm trying to generate my database from classes using NHibernate 2.1.2
with Rhino Commons, but the schema that's being created contains a
column for the class. For the most part this wouldn't matter but one
class in particular is causing this to fail... my Order class (because
order is a reserved keyword in SQL - yes maybe I should have used a
word that wasn't a keyword but that's another issue). Can someone help
explain what's causing this and what I can do to fix it.

Orders.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<class name="Order" table="Orders">
    <id name="_persistenceID" column="ID" type="Guid" access="field"
unsaved-value="00000000-0000-0000-0000-000000000000">
        <generator class="guid.comb" />
    </id>
    <version name="_persistenceVersion" column="Version"
access="field" type="int" unsaved-value="0" />

    <property name="DateDeleted" column="DateDeleted" type="DateTime" /
>
    <property name="ChangeReason" column="ChangeReason" type="String"
not-null="true" />
    <property name="CompletedDate" column="CompletedDate"
type="DateTime" />
    <property name="IsDeleted" column="IsDeleted" type="Boolean" />
    <property name="Notes" column="Notes" type="String" />
    <property name="OrderDate" column="OrderDate" type="DateTime" not-
null="true" />
    <property name="OrderTotal" column="OrderTotal" type="Decimal" />
    <property name="RequiredDate" column="RequiredDate"
type="DateTime" />

    <many-to-one name="Customer" column="Customer" class="Customer"
not-null="true" />

    <bag name="OrderDetails" table="OrderDetails" generic="true"
cascade="all">
        <key column="OrderDetail" foreign-key="FK_OrderOrderDetails" /
>
        <one-to-many class="OrderDetail" />
    </bag>

</class>
produces the following SQL:

    create table Orders (
  ID UNIQUEIDENTIFIER not null,
   Version INT not null,
   DateDeleted DATETIME null,
   ChangeReason NVARCHAR(255) not null,
   CompletedDate DATETIME null,
   IsDeleted BIT null,
   Notes NVARCHAR(255) null,
   OrderDate DATETIME not null,
   OrderTotal DECIMAL(19,5) null,
   RequiredDate DATETIME null,
   Customer UNIQUEIDENTIFIER not null,
   Order UNIQUEIDENTIFIER null,
   primary key (ID)
)
It's that 2nd to last column (Order) that's causing this to be invalid
and highlighted the issue. It is happening on all my other classes -
but I've no idea why. What can I do about it?

The other end of the mapping OrderDetails.hbm.xml:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="TheWorkshop.DomainModel" namespace="TheWorkshop.DomainModel"
default-access="field.camelcase-underscore" default-lazy="true">

<class name="OrderDetail" table="OrderDetails">
    <id name="_persistenceID" column="ID" type="Guid" access="field"
unsaved-value="00000000-0000-0000-0000-000000000000">
        <generator class="guid.comb" />
    </id>
    <version name="_persistenceVersion" column="Version"
access="field" type="int" unsaved-value="0" />

    <property name="AdjustedPrice" column="AdjustedPrice"
type="Decimal" not-null="true" />
    <property name="LineCost" column="LineCost" type="Decimal" not-
null="true" />
    <property name="Notes" column="Notes" type="String" />
    <property name="Photo" column="Photo" type="String" />
    <property name="Price" column="Price" type="Decimal" not-
null="true" />
    <property name="Quantity" column="Quantity" type="int" />

    <many-to-one name="`Order`" column="`Order`" class="Order" not-
null="true" />
    <many-to-one name="Product" column="Product" class="Product" not-
null="true" />

</class>
and that generates the following:

create table OrderDetails (
ID UNIQUEIDENTIFIER not null,
Version INT not null,
AdjustedPrice DECIMAL(19,5) not null,
LineCost DECIMAL(19,5) not null,
Notes NVARCHAR(255) null,
Photo NVARCHAR(255) null,
Price DECIMAL(19,5) not null,
Quantity INT null,
[Order] UNIQUEIDENTIFIER not null,
Product UNIQUEIDENTIFIER not null,
primary key (ID)
)

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to