NHibernate *.hbm.xml 文档
Posted &碎梦
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NHibernate *.hbm.xml 文档相关的知识,希望对你有一定的参考价值。
# class
<class
name="ClassName" (1)
table="tableName" (2)
discriminator-value="discriminator_value" (3)
mutable="true|false" (4)
schema="owner" (5)
proxy="ProxyInterface" (6)
dynamic-update="true|false" (7)
dynamic-insert="true|false" (8)
select-before-update="true|false" (9)
polymorphism="implicit|explicit" (10)
where="arbitrary sql where condition" (11)
persister="PersisterClass" (12)
batch-size="N" (13)
optimistic-lock="none|version|dirty|all" (14)
lazy="true|false" (15)
abstract="true|false" (16)
/>
(1) name: The fully qualified .NET class name of the persistent class (or interface), including its assembly name.
(2) table(optional - defaults to the unqualified class name): The name of its database table.
(3) discriminator-value (optional - defaults to the class name): A value that distinguishes individual subclasses, used for polymorphic behaviour. Acceptable values include null and not null.
(4) mutable (optional, defaults to true): Specifies that instances of the class are (not) mutable.
(5) schema (optional): Override the schema name specified by the root <hibernate-mapping> element.
(6) proxy (optional): Specifies an interface to use for lazy initializing proxies. You may specify the name of the class itself.
(7) dynamic-update (optional, defaults to false): Specifies that UPDATE SQL should be generated at runtime and contain only those columns whose values have changed.
(8) dynamic-insert (optional, defaults to false): Specifies that INSERT SQL should be generated at runtime and contain only the columns whose values are not null.
(9) select-before-update (optional, defaults to false): Specifies that NHibernate should never perform an SQL UPDATE unless it is certain that an object is actually modified. In certain cases (actually, only when a transient object has been associated with a new session using update()), this means that NHibernate will perform an extra SQL SELECT to determine if an UPDATE is actually required.
(10) polymorphism (optional, defaults to implicit): Determines whether implicit or explicit query polymorphism is used.
(11) where (optional) specify an arbitrary SQL WHERE condition to be used when retrieving objects of this class
(12) persister (optional): Specifies a custom IClassPersister.
(13) batch-size (optional, defaults to 1) specify a "batch size" for fetching instances of this class by identifier.
(14) optimistic-lock (optional, defaults to version): Determines the optimistic locking strategy.
(15) lazy (optional): Lazy fetching may be completely disabled by setting lazy="false".
(16) abstract (optional): Used to mark abstract superclasses in <union-subclass> hierarchies.
# id
<id
name="PropertyName" (1)
type="typename" (2)
column="column_name" (3)
unsaved-value="any|none|null|id_value" (4)
access="field|property|nosetter|ClassName(5)">
<generator class="generatorClass"/>
(1) name (optional): The name of the identifier property.
(2) type (optional): A name that indicates the NHibernate type.
(3) column (optional - defaults to the property name): The name of the primary key column.
(4) unsaved-value (optional - defaults to a "sensible" value): An identifier property value that indicates that an instance is newly instantiated (unsaved), distinguishing it from transient instances that were saved or loaded in a previous session.
(5) access (optional - defaults to property): The strategy NHibernate should use for accessing the property value.
</id>
# property
<property
name="propertyName" (1)
column="column_name" (2)
type="typename" (3)
update="true|false" (4)
insert="true|false" (4)
formula="arbitrary SQL expression" (5)
access="field|property|ClassName" (6)
optimistic-lock="true|false" (7)
generated="never|insert|always" (8)
lazy="true|false" (9)
/>
(1) name: the name of the property of your class.
(2) column (optional - defaults to the property name): the name of the mapped database table column.
(3) type (optional): a name that indicates the NHibernate type.
(4) update, insert (optional - defaults to true) : specifies that the mapped columns should be included in SQL UPDATE and/or INSERT statements. Setting both to false allows a pure "derived" property whose value is initialized from some other property that maps to the same column(s) or by a trigger or other application.
(5) formula (optional): an SQL expression that defines the value for a computed property. Computed properties do not have a column mapping of their own.
(6) access (optional - defaults to property): The strategy NHibernate should use for accessing the property value.
(7) optimistic-lock (optional - defaults to true): Specifies that updates to this property do or do not require acquisition of the optimistic lock. In other words, determines if a version increment should occur when this property is dirty.
(8) generated (optional - defaults to never): Specifies that this property value is actually generated by the database. See the discussion of Section 5.5, “Generated Properties”.
(9) lazy (optional - defaults to false): Specifies that this property is lazy. A lazy property is not loaded when the object is initially loaded, unless the fetch mode has been overridden in a specific query. Values for lazy properties are loaded when any lazy property of the object is accessed.
以上是关于NHibernate *.hbm.xml 文档的主要内容,如果未能解决你的问题,请参考以下文章
NHibernate.MappingException:没有持久性:XYZ
NHibernate错误:Could not compile the mapping document的解决
NHibernate:no persister for 异常