How to change the property name through conventions?

Lars's Avatar

Lars

07 Mar, 2010 06:38 PM via web

Hi,
I'm having a problem with reserved names in Oracle during automapping schemaExport.
The schema export generates the following DDL:

create table MYTABLE (

   id RAW(16) not null,
   Comment NVARCHAR2(255),
   primary key (id)
)

When executed i get an ORA-00904: : invalid identifier exception.
It seems like 'COMMENT' name is a reserved field
if i change comment -> comment the sql executes propertly.
How can i change comment -> comment
using the convention interface in Fluent?

regards,
Lars.

  1. 2 Posted by Lars on 07 Mar, 2010 06:41 PM

    Lars's Avatar

    hmm html formating issues:

    comment -> comment___

  2. Support Staff 3 Posted by James Gregory on 09 Mar, 2010 02:44 PM

    James Gregory's Avatar

    Hey Lars,

    You should look into creating an IPropertyConvention, and use the Column method to change the column name.

    Something like this should work:

    public class ReservedKeywordConvention : IPropertyConvention, IPropertyConventionAcceptance
    {
      public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
      {
        criteria.Expect(x => x.Name == "Comment");
      }
    
      public void Apply(IPropertyInstance instance)
      {
        instance.Column(instance.Name + "_");
      }
    }
    

    You should also consider looking into the hbm2ddl.keywords NHibernate property, which can do auto-escaping of reserved keywords.

  3. James Gregory closed this discussion on 18 Mar, 2010 12:17 PM.

Comments are currently closed for this discussion. You can start a new one.