一个典型的Hibernate多对一关联配置

本文介绍了一个使用Hibernate框架进行数据库映射的具体示例。该示例展示了如何将UserInfo类映射到'user_info'表,并定义了包括登录名、密码等属性的详细映射规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" 
>
    
<hibernate-mapping>
<!-- 
    Created by the Middlegen Hibernate plugin 2.1

    http://boss.bekk.no/boss/middlegen/
    http://www.hibernate.org/
-->

<class 
    
name="cn.hand.kmoa.persistence.UserInfo" 
    table
="user_info"
    schema
="test"
    dynamic-update
="true"
    dynamic-insert
="true"
>
    
<meta attribute="class-description" inherit="false">
       @hibernate.class
        table="user_info"
        schema="test"
        dynamic-update="true"
        dynamic-insert="true"
    
</meta>

    
<id
        
name="id"
        type
="java.lang.Integer"
        column
="ID"
    
>
        
<meta attribute="field-description">
           @hibernate.id
            generator-class="assigned"
            type="java.lang.Integer"
            column="ID"


        
</meta>
        
<generator class="assigned" />
    
</id>

    
<property
        
name="loginName"
        type
="java.lang.String"
        column
="LoginName"
        not-null
="true"
        length
="20"
    
>
        
<meta attribute="field-description">
           @hibernate.property
            column="LoginName"
            length="20"
            not-null="true"
        
</meta>    
    
</property>
    
<property
        
name="password"
        type
="java.lang.String"
        column
="Password"
        not-null
="true"
        length
="20"
    
>
        
<meta attribute="field-description">
           @hibernate.property
            column="Password"
            length="20"
            not-null="true"
        
</meta>    
    
</property>
    
<property
        
name="trueName"
        type
="java.lang.String"
        column
="TrueName"
        not-null
="true"
        length
="10"
    
>
        
<meta attribute="field-description">
           @hibernate.property
            column="TrueName"
            length="10"
            not-null="true"
        
</meta>    
    
</property>
    
<many-to-one name="departId" class="cn.hand.kmoa.persistence.DeptInfo" column="DepartID" cascade="all" />
    
<many-to-one name="position" class="cn.hand.kmoa.persistence.PostInfo" column="Position" cascade="all" />
    
    
<property
        
name="sex"
        type
="int"
        column
="Sex"
        not-null
="true"
        length
="2"
    
>
        
<meta attribute="field-description">
           @hibernate.property
            column="Sex"
            length="2"
            not-null="true"
        
</meta>    
    
</property>
    
<property
        
name="phone"
        type
="java.lang.String"
        column
="Phone"
        length
="12"
    
>
        
<meta attribute="field-description">
           @hibernate.property
            column="Phone"
            length="12"
        
</meta>    
    
</property>
    
<property
        
name="mobile"
        type
="java.lang.String"
        column
="Mobile"
        length
="11"
    
>
        
<meta attribute="field-description">
           @hibernate.property
            column="Mobile"
            length="11"
        
</meta>    
    
</property>
    
<property
        
name="mail"
        type
="java.lang.String"
        column
="Mail"
        length
="50"
    
>
        
<meta attribute="field-description">
           @hibernate.property
            column="Mail"
            length="50"
        
</meta>    
    
</property>
    
<property
        
name="remark"
        type
="java.lang.String"
        column
="Remark"
        length
="255"
    
>
        
<meta attribute="field-description">
           @hibernate.property
            column="Remark"
            length="255"
        
</meta>    
    
</property>

    
<!-- Associations -->

</class>
</hibernate-mapping>
User表与Dept和Post表的主键的一队多关联
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值