站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Hibernate reference 3.2.0 ga 正式版中文参考手册

22.2. Hibernate 映射 - Hibernate reference 3.2.0 ga 正式版中文参考手册

22.2. Hibernate 映射

下列的XML映射应该是很直白的。

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="eg">
    <class 
        name="Blog" 
        table="BLOGS" >
        
        <id 
            name="id" 
            column="BLOG_ID">
            
            <generator class="native"/>
            
        </id>
        
        <property 
            name="name" 
            column="NAME" 
            not-null="true" 
            unique="true"/>
            
        <bag 
            name="items" 
            inverse="true" 
            order-by="DATE_TIME" 
            cascade="all">
            
            <key column="BLOG_ID"/>
            <one-to-many class="BlogItem"/>
            
        </bag>
        
    </class>
    
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="eg">
    
    <class 
        name="BlogItem" 
        table="BLOG_ITEMS" 
        dynamic-update="true">
        
        <id 
            name="id" 
            column="BLOG_ITEM_ID">
            
            <generator class="native"/>
            
        </id>
        
        <property 
            name="title" 
            column="TITLE" 
            not-null="true"/>
            
        <property 
            name="text" 
            column="TEXT" 
            not-null="true"/>
            
        <property 
            name="datetime" 
            column="DATE_TIME" 
            not-null="true"/>
            
        <many-to-one 
            name="blog" 
            column="BLOG_ID" 
            not-null="true"/>
            
    </class>
    
</hibernate-mapping>