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

<hibernate-mapping package="org.hibernate.test.querycache">
	
	<class name="Course">
		<id name="courseCode">
			<generator class="assigned"/>
		</id>
		<property name="description"/>
        <set name="courseMeetings" inverse="true" cascade="all-delete-orphan" lazy="false">
            <key column="courseCode"/>
            <one-to-many class="CourseMeeting"/>
        </set>
	</class>

    <class name="CourseMeeting">
        <composite-id name="id" class="CourseMeetingId">
            <key-property name="courseCode"/>
            <key-property name="day"/>
            <key-property name="period"/>
            <key-property name="location"/>
        </composite-id>
        <many-to-one name="course" insert="false" update="false" lazy="false">
            <column name="courseCode"/>
        </many-to-one>
    </class>

	<class name="Student">
		<id name="studentNumber">
		    <column name="studentId"/>
			<generator class="assigned"/>
		</id>
        <component name="name">
            <property name="first" column="name_first" not-null="true"/>
            <property name="middle" column="name_middle" not-null="false"/>
            <property name="last" column="name_last" not-null="true"/>
        </component>
		<set name="enrolments" inverse="true" cascade="delete">
			<key column="studentId"/>
			<one-to-many class="Enrolment"/>
		</set>
        <map name="addresses" table="addresses" cascade="all,delete" lazy="true">
            <key column="studentNumber"/>
            <map-key column="addressType" type="string"/>
            <one-to-many class="Address"/>
        </map>
        <many-to-one name="preferredCourse" column="preferredCourseCode" lazy="proxy"/>
        <list name="secretCodes" lazy="false">
            <key>
                <column name="studentNumber"/>
            </key>
            <index column="i"/>
            <element column="secretCode" type="int"/>
        </list>
	</class>

    <class name="Address">
        <id name="id">
			<generator class="increment"/>
		</id>
        <property name="addressType"/>
        <property name="street"/>
        <property name="city"/>
        <property name="stateProvince"/>
        <property name="postalCode"/>
        <property name="country"/>
        <many-to-one name="student" class="Student" column="studentNumber" not-null="false"/>
    </class>

	<class name="Enrolment">
		<composite-id>
			<key-property name="studentNumber">
				<column name="studentId"/>
			</key-property>
			<key-property name="courseCode"/>
		</composite-id>
		<many-to-one name="student" insert="false" update="false" lazy="proxy">
			<column name="studentId"/>
		</many-to-one>
		<many-to-one name="course" insert="false" update="false" lazy="false">
			<column name="courseCode"/>
		</many-to-one>
		<property name="semester" type="short" not-null="true"/>
		<property name="year" column="`year`" type="short" not-null="true"/>
	</class>

</hibernate-mapping>
