Hibernate映射文件配置属性解释
例子:(*.hbm.xml)
<hibernate-mapping>
<class name="com.mr.user.User" table="test3">
<id name="id">
<generator class=""></generator>
</id>
<property name="username" length="45" not-null="true" column="username"/>
<property name="password" length="45" not-null="true" column="password"/>
<property name="realname" length="20" column="realname"/>
<property name="address" length="45" column="address"/>
<property name="email" length="45" column="email"/>
</class>
</hibernate-mapping>
解释:
<class>标签主要用于指定持久化类和数据库表名
“name”属性指定持久化类得全局路径
“table”属性指定数据库表名
class标签包含一个<id>,和多个<property>
<id>元素用于持久化类的唯标识与数据库表的主键字段的映射,通过<generator>定义主键的生成策略
<property>标签属性,用于持久化类的其他属性和数据表中的非主键字段的映射:
name:持久化类属性名,以小写字母开头
column:数据库字段名
type:数据库字段类型
length:数据库字段定义的长度
not-null:布尔变量,指定字段是否为空
unique:布尔变量,指定字段是否唯一
lazy:布尔变量,指定是否延迟抓取
Hibernate主键策略的常用配置属性: