hibernate 映射文件解释 property


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)
        lazy="true|false"                                            (7)
        unique="true|false"                                          (8)
        not-null="true|false"                                        (9)
        optimistic-lock="true|false"                                 (10)
        node=element-name|@attribute-name|element/@attribute|.       (11)
/>
(1) name: 对象属性的名称
(2) type: 对象属性的类型
(3) column:对象属性对应数据库中主键字段的名称
(4)update/insert: 能否对此字段进行更新/插入操作
(5) formula:通过查询语句来获取值,例如:
     <property name="totalPrice"
    formula="( SELECT SUM (li.quantity*p.price) FROM LineItem li, Product p
                WHERE li.productId = p.productId
                AND li.customerId = customerId
                AND li.orderNumber = orderNumber )"/>
(6)access:field--直接通过读取属性变量来获取值
             property--通过get,set方法获取
             ClassName--还不清楚这种情况,知道的说一声阿
(7) lazy:在第一次被获取时,变量值是否被读取。
(8,9)hibernate 为你增加惟一和非空验证
(10)optimistic-lock:当前字段是否被应用到乐观锁定。
  
(11) node:不清楚作用还……
 

你可能感兴趣的:(hibernate 映射文件解释 property)