Hibernate mapping file property description

1. <hibernate-mapping ...>
1.default-cascade: Set the cascade style, the default is none. When configuring Java property mapping and collection mapping, the cascade property can be specified. If not specified, the cascade style specified here is adopted;
2.default-lazy: Set the lazy loading strategy, the default is true. When configuring Java property mapping and collection mapping, the lazy property can be specified. If not specified, the lazy property specified here is used (usually it is not recommended to close it. For example, a Teacher object is associated with N Student objects. If lazy loading is disabled, hibernate When loading the Teacher object, all the Student objects will be automatically loaded. If the program only needs to access the Teacher object, loading the Student object is purely redundant);
3.default-access: Set the property access policy, the default property, that is, use the getter/setter method to Access attributes, such as
specifying access="field", access member variables through reflection There are two persistent mappings with the same class name in the file, under different package structures, with different fully-qualified class names, but still two different classes. At this time, auto-import="false" should be set, otherwise hibernate cannot distinguish) ;
5.package: specify a package prefix, if the fully qualified class name is not specified in the mapping file, the prefix will be used by default;
6.schema: specify the schema name of the mapped database;
7.catalog: specify the catalog of the mapped database name;

 

2. <class...>
1.table: Specify the table name of the persistent class mapping;
2.discriminator-value: Specify the value to distinguish different subclasses, when using the <subclass...> element to define the persistent class This property needs to be used when the inheritance relationship is mapped;
3.mutable: specify whether the instance of the persistent class is a mutable object or an immutable object, and the value is true or false;
4.proxy: specify an interface, which is used as a proxy in lazy loading;
5. dynamic-update: specify whether the update statement is dynamically generated at runtime, and only update those fields that have changed, the default is false; (when dynamic-update is turned on, the mapping file can specify these kinds of optimistic locking strategies [version , all, dirty, none], it is recommended to use version)
6.dynamic-insert: specify whether the insert statement is dynamically generated at runtime, and only insert those non-empty fields, the default is false;
7.select-before-update: specify update Whether you need to select before, the default is false; it will reduce performance after it is turned on. If the state of the object changes frequently, it is recommended to set it to false;
8. polymorphism: When the <union-subclass ...> element is used to configure the inheritance mapping, this element Specify whether to use implicit polymorphic query, the default value is implicit;
9.where: specify a sql statement filter condition for an attachment;
10.persister: specify a custom ClassPersister, usually no need to specify this attribute;
11.batch-size: specify The number of instances to be fetched in each batch when fetching instances according to the identifier, the default is 1;
12.optimistic-lock: specifies the optimistic locking strategy, the default is version;
13.check: specifies an sql expression to specify a multi-row Check constraint for the table corresponding to the persistent class;
14.subselect: for Mapping immutable, read-only entities;

 

3. <id ...>
1. <id ...> is used to specify the identification attribute of the persistent class; 2.name: the
name of the identification attribute;
3.type: the data type;
4.column: the column name of the data column ;
5.unsaved-value: Specifies the value of the identity attribute when an instance is just created and has not been saved. Distinguish the instance that was loaded by the previous session but not persisted again;
6.access: override the default-access in <hibernate-mapping...>;

 

Fourth, the primary key generator
1.increment
2.identity
3.sequence
4.hilo
5.seqhilo
6.uuid
7.guid
8.native
9.assigned
10.select
11.foreign

 

5. <property...>
1.<property...> is used to specify common properties of persistent classes;
2.name: common property name;
3.type: data type, which can be Integer, String, date, timestamp , float, binary, character, object, etc., can be the class name of a serializable Java class, or a user-defined class name;
4. update, insert: used to set whether the generated update or insert statement is required Include this field, the default is true;
5.formula: specify a sql expression, the value of the specified attribute will be calculated according to the expression, the calculated attribute has no data column corresponding to it;
6.lazy: whether to delay loading, the default is false;
7.unique: whether to add a unique constraint to the data column;
8.not-null: whether to add a not-null constraint to the data column;
9.optimistic-lock: set whether the attribute needs to use optimistic locking when updating, the default is true ;
10.generated: Set whether the value of the data column mapped by the attribute is generated by the database. This attribute can accept never (not generated by the database), insert (generated during insert, and will not be regenerated during subsequent updates), always (in Both insert and update will be regenerated)
11. index: specify a string index name, when hibernate automatically builds a table, it is used to create an index for the data column mapped by the attribute, thereby speeding up the query based on the data column;
12.unique_key: Specify the name of a unique key; when hibernate automatically builds a table, it is used to create a unique index for the data column mapped by this attribute, which is valid only when the data column has a unique constraint;
13.length: the field length of the data column;
14.precision: specify the number of significant digits of the
data column mapped by this attribute; 15.scale: specify the decimal place of the data column mapped by this attribute;

 

6. Other
1. Class elements can also specify lazy, schema, catalog and other attributes to override the default behavior specified in hibernate-mapping;
2. <hibernate-mapping ...> can contain multiple <class ... >, but the usual practice is that a persistent class corresponds to a mapping file;
3. <subclass ...>, <joined-subclass ...>, <union-subclass ...> can be added to <class ...> >, these elements are used to define subclasses;

 

7. Examples

<?xml version="1.0" encoding="gb2312"?>
<!-- Specify the DTD information of the Hiberante3 mapping file-->
<!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 " http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ">
<!-- hibernate-mapping is the root element of the mapping file -->
<hibernate-mapping package="persistence" schema=" ad" >
 <!-- Each class element corresponds to a persistent object-->
 <class name="News" table="news_table">
  <!-- The id element defines the identification attribute of the persistent class-->
  <id name="id" >
   <!-- Specify the primary key generation strategy-->
   <generator class="identity"/>
  </id>
  <!-- The property element defines general properties -->
  <property name="title"/>
  <property name="content"/>
 </class>
</hibernate-mapping>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326873750&siteId=291194637