<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (c) Members of the EGEE Collaboration. 2006-2009.
    See http://www.eu-egee.org/partners/ for details on the copyright holders.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    Authors:
    	Andrea Ceccanti (INFN)

-->

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

<hibernate-mapping>
	<class name="org.glite.security.voms.admin.persistence.model.VOMSUser" table="usr">

		<id name="id" column="userid" type="java.lang.Long">
			<generator class="native" >
				<param name="sequence">VOMS_USR_SEQ</param>
			</generator>
		</id>

		<property name="dn" type="java.lang.String" update="true"
			insert="true" column="dn" unique="false" />

		<many-to-one
			name="ca"
			column="ca"
			class="org.glite.security.voms.admin.persistence.model.VOMSCA" foreign-key="fk_usr_ca"/>
			
		<!-- Compatibility: old fields -->
        <!-- 
		<property name="cn" type="java.lang.String" column="cn"/>
		<property name="certURI" type="java.lang.String" column="cauri"/>
        -->
		
		<!-- New ( >= 2.5 ) Membership information  -->
		<property name="name" type="java.lang.String" column="name" not-null="true"/>
		<property name="surname" type="java.lang.String" column="surname" not-null="true"/>
		<property name="institution" type="java.lang.String" column="institution" not-null="true"/>
		<property name="address" type="text" column="address" not-null="true"/>
		
		<property name="phoneNumber" type="java.lang.String" column="phone_number" not-null="true"/>
    
		<property name="emailAddress" type="java.lang.String" column="email_address" not-null="true"/>
		
		
		<!-- Membership creation time and validity end time -->
		<property name="creationTime" type="timestamp" column="creation_time"/>
		<property name="endTime" type="timestamp" column="end_time"/>
		
		<set name="mappings" sort="natural"  cascade="all-delete-orphan" inverse="true">
			<key column="userid" on-delete="cascade"/>
			<one-to-many class="org.glite.security.voms.admin.persistence.model.VOMSMapping"/>			
		</set>
		
		<set name="attributes" cascade="all-delete-orphan" inverse="true">
			<key column="u_id" on-delete="cascade"/>
			<one-to-many class="org.glite.security.voms.admin.persistence.model.VOMSUserAttribute"/>
		</set>
	
		<!-- Multiple certificates support -->
		<set name="certificates" cascade="all-delete-orphan" inverse="true">
			<key column="usr_id" on-delete="cascade"/>
			<one-to-many class="org.glite.security.voms.admin.persistence.model.Certificate"/>
		</set>
    
        <!-- AUP acceptance records -->
        <set name="aupAcceptanceRecords" cascade="all-delete-orphan" inverse="true">
          <key column="usr_id" on-delete="cascade"/>
          <one-to-many class="org.glite.security.voms.admin.persistence.model.AUPAcceptanceRecord"/>
        </set>
        
        <set name="tasks" lazy="false" inverse="true" cascade="all-delete-orphan">
          <key column="usr_id" on-delete="cascade"/>
          <one-to-many class="org.glite.security.voms.admin.persistence.model.task.Task"/>        
        </set>
        
        <set name="personalInformations" cascade="all-delete-orphan" lazy="false">
          <key column="usr_id"/>
          <one-to-many class="org.glite.security.voms.admin.persistence.model.personal_info.PersonalInformationRecord"/>        
        </set>
	</class>

</hibernate-mapping>
