日期:2014-05-20  浏览次数:20761 次

hibernate 多对一联表查询

Java code

import java.util.Date;

/**
 * Weather entity. @author MyEclipse Persistence Tools
 */

public class Weather implements java.io.Serializable {

    // Fields

    private String guid;
    [color=#FF0000]private Station station;[/color]
    private Date date;
    private Date spiderDate;
    private Short week;
    private String bwea;
    private String ewea;
    private Short tmax;
    private Short tmin;
    private String bwind;
    private String ewind;
    private String bwindPower;
    private String ewindPower;

    // Constructors

    /** default constructor */
    public Weather() {
    }

    /** full constructor */
    public Weather(Station station, Date date, Date spiderDate, Short week,
            String bwea, String ewea, Short tmax, Short tmin, String bwind,
            String ewind, String bwindPower, String ewindPower) {
        this.station = station;
        this.date = date;
        this.spiderDate = spiderDate;
        this.week = week;
        this.bwea = bwea;
        this.ewea = ewea;
        this.tmax = tmax;
        this.tmin = tmin;
        this.bwind = bwind;
        this.ewind = ewind;
        this.bwindPower = bwindPower;
        this.ewindPower = ewindPower;
    }

    get(),set()...............

}


XML code

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.scyb.iptv.weather.common.bo.Weather" table="weather" catalog="weather_info">
        <id name="guid" type="java.lang.String">
            <column name="GUID" length="32" />
            <generator class="uuid.hex" />
        </id>
        [color=#FF0000]<many-to-one name="station" class="com.scyb.iptv.weather.common.bo.Station">
            <column name="STATION_NO" length="32" unique="true">
                <comment>站点号</comment>
            </column>
        </many-to-one>[/color]
        <property name="date" type="java.util.Date">
            <column name="DATE" length="10">
                <comment>天气日期</comment>
            </column>
        </property>
        <property name="spiderDate" type="java.util.Date">
            <column name="SPIDER_DATE" length="10">
                <comment>爬虫日期</comment>
            </column>
        </property>
        <property name="week" type="java.lang.Short">
            <column name="WEEK">
                <comment>星期</comment>
            </column>
        </property>
        <property name="bwea" type="java.lang.String">
            <column name="BWEA" length="6">
                <comment>白天天气</comment>
            </column>
        </property>
        <property name="ewea" type="java.lang.String">
            <column name="EWEA" length="6">
                <comment>夜间天气</comment>
            </column>
        </property>
        <property name="tmax" type="java.lang.Short">
            <column name="TMAX">
                <comment>最高温度</comment>
            </column>
        </property>
        <property name="tmin" type="java.lang.Short">
            <column name="TMIN">
                <comment>最低温度</comment>
            </column>
        </property>
        <property name="bwind" type="java.lang.String">
            <column name="BWIND" length="6">
                <comment>白天风向</comment>
            </column>
        </property>
        <property name="ewind" type="java.lang.String">
            <column name="EWIND" length="6">
                <comment>夜间风向</comment>
            </column>
        </property>
        <property name="bwindPower" type="java.lang.String">
            <column name="BWIND_POWER" length="8">
                <comment>白天风力</comment>
            </column>
        </property>
        <property name="ewindPower" type="java.lang.String">
            <column name="EWIND_POWER" length="8">
                <comment>夜间风力</comment>
            </column>
        </property>
    </class>
</hibernate-mapping>