There are two kinds of classes in NHibernate:
NHibernate uses mapping XML files to define the mapping metadata. Each mapping file can contain metadata for one or many classes. PowerDesigner uses the following grouping strategy:
A separate mapping file is generated for each single entity class that is not in an inheritance hierarchy.
A separate mapping file is generated for each inheritance hierarchy that has a unique mapping strategy. All mappings of subclasses are defined in the mapping file. The mapping file is generated for the root class of the hierarchy.
No mapping file is generated for a single value type class that is not in an inheritance hierarchy. Its mapping is defined in its owner's mapping file.
Classes can be mapped to tables or views. Since views have many constraints and limited functionality (for example they do not have primary keys and reference keys), some views cannot be updated, and the mappings may not work properly in some cases.
There are some conditions that need to be met in order to generate mapping for a specific class:
The source can be generated. This may not be possible if, for example, the visibility of the class is private.
The class is persistent.
The generation mode is not set to Generate ADT (abstract data type) and Value Type.
If the class is an inner class, it must be static, and have public visibility. NHibernate should then be able to create instances of the class.
NHibernate specific class mapping options are defined in the NHibernate tab of the class property sheet:
Option |
Description |
---|---|
Dynamic insert |
Specifies that INSERT SQL should be generated at runtime and will contain only the columns whose values are not null. NHibernate Tag: dynamic-insert |
Dynamic update |
Specifies that UPDATE SQL should be generated at runtime and will contain only the columns whose values have changed. NHibernate Tag: dynamic-update |
Select before update |
Specifies that NHibernate should never perform a SQL UPDATE unless it is certain that an object is actually modified. NHibernate Tag: select-before-update |
Default cascade |
Specifies the default cascade style. NHibernate Tag: default-cascade |
Default access |
Specifies the default access type (field or property) NHibernate Tag: default-access |
Proxy name |
Specifies an interface to use for lazy initializing proxies. NHibernate Tag: proxy |
Batch size |
Specifies a "batch size" for fetching instances of this class by identifier. NHibernate Tag: batch-size |
Check |
Specifies a SQL expression used to generate a multi-row check constraint for automatic schema generation. NHibernate Tag: check |
Polymorphism |
Specifies whether implicit or explicit query polymorphism is used. NHibernate Tag: polymorphism |
Schema name |
Specifies the name of the database schema. NHibernate Tag: schema |
Catalog name |
Specifies the name of the database catalog. NHibernate Tag: catalog |
Row id |
Specifies that NHibernate can use the ROWID column on databases which support it (for example, Oracle). NHibernate Tag: rowed |
Persister class name |
Specifies a custom persistence class. NHibernate Tag: persister |
Lazy |
Specifies that the class should be lazy fetching. NHibernate Tag: lazy |
Mutable |
Specifies that instances of the class are mutable. NHibernate Tag: mutable |
Abstract class |
Specifies that the class is abstract. NHibernate Tag: abstract |
Auto import |
Specifies that an unqualified class name can be used in a query NHibernate Tag: Auto-import |
Discriminator column |
Specifies the discriminator column or formula for polymorphic behavior in a one table per hierarchy mapping strategy. NHibernate Tag: discriminator |
Discriminator value |
Specifies a value that distinguishes individual subclasses, which are used for polymorphic behavior. NHibernate Tag: discriminator-value |
Discriminator type |
Specifies the discriminator type. NHibernate Tag: type |
Force usage of discriminator |
Forces NHibernate to specify allowed discriminator values even when retrieving all instances of the root class. NHibernate Tag: force |
Do not use discriminator in insert |
Forces NHibernate to not include the column in SQL INSERTs NHibernate Tag: insert |
Optimistic lock type |
Specifies an optimistic locking strategy. NHibernate Tag: optimistic-lock |
Optimistic lock column name |
Specifies the column used for optimistic locking. A field is also generated if this option is set. NHibernate Tag: version/ timestamp |
Optimistic lock unsaved value |
Specifies whether an unsaved value is null or undefined. NHibernate Tag: unsaved-value |