2

I have a little doubt for mapping of property in hbm file.

Sometimes I've mapped the string field of my db in this way:

<property name="MyPropName" column="MyColumnName" length="20" />

but the same mapping can be wrote in this way:

<property name="MyPropName" column="MyColumnName" type="String(20)" />

my question is...what's the better way?

If I omit "type" attributes for property tags it works, but I don't know if there are some contraindications. Can you tell me?

And last thing...are right this associations?

db varchar fields -> type "AnsiString"

db nvarchar fields -> type "String"

Luca Petrini
  • 1,695
  • 2
  • 28
  • 53

1 Answers1

1

The "best practice" is to only override the defaults. So, for your example, the first form would be the best.

As for the second question: yes, they are correct.

You can find all the value types and default mappings here: 5.2.2. Basic value types

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
  • Just a doubt...in terms of performance there are any difference from write or omit the "type" attribute? If I don't write the "type" attribute NHibernate get type by reflection, but I don't know if it does same thing also when the "type" is specified. Can you tell me? – Luca Petrini Oct 29 '10 at 06:48
  • Considering initialization happens just ONCE in your app lifetime, it really doesn't matter at all. – Diego Mijelshon Oct 29 '10 at 12:18
  • Thanks, I suppose that this inizialization has done when NHibernate build the configuration...right? – Luca Petrini Oct 29 '10 at 16:27