views:

43

answers:

2

I'm playing with Hibernate a little bit. I created a "Group" class and a XML schema tied to it. Unfortunately when I try to export that schema, my .NET complains about a syntax error. I'm pretty sure my schema is malformed, but is there any technique to help troubleshooting ?

My XML schema looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="Folke"
               namespace="Folke.Code.Domain">
  <class name="Group">
    <id name="Id">
      <generator class="native"></generator>
    </id>
    <property name="SiteId" />
    <property name="Name" index="GroupName"/>
  </class>
</hibernate-mapping>

ASP.NET complains that there's a syntax error here:

new SchemaExport(HibernateModule.CurrentConfiguration).Execute(false, true, false, false);

The syntax error being "near Group" I'm pretty sure the problem is in the Group schema, but, again, I have no idea where to look to get a bit more details.

+2  A: 

"Group" is a reserved word in SQL (part of GROUP BY clause name).

Consider either naming your class differently or explicitly specifying different table name via table attribute in class mapping:

<class name="Group" table="MyGroups">
ChssPly76
Ding ding ding, we have a winner.
Will Shaver
+1  A: 

If you want to keep the Group table name you can quote it using the backtick character in the table attribute of your class mapping. eg:

<class name="Group" table="`Group`">

This will result in the table name being quoted in whatever dialect you are using when the SQL is generated. eg [Group] in MSSQL T-Sql or "Group" in DB2 SQL.

I Am The Enterprise