<?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">

<hibernate-mapping
    default-lazy="false"
    auto-import="true"
    default-access="property"
    default-cascade="all"
    package="gov.va.med.esr.common.model.person">

  <class name="Association"
         table="PERSON_CONTACT">

    <id name="identifier"
        type="big_decimal"
        column="PERSON_CONTACT_ID">
      <generator class="gov.va.med.fw.persistent.hibernate.BigSequenceGenerator">
        <param name="sequence">transaction_s</param>
      </generator>
    </id>

    <version name="version" type="integer" column="RECORD_MODIFIED_COUNT"/>

    <many-to-one name="person" lazy="false" class="Person" cascade="none">
      <column name="PERSON_ID" not-null="true"/>
    </many-to-one>

    <many-to-one name="type" class="gov.va.med.esr.common.model.lookup.AssociationType"
                 outer-join="false" cascade="none" column="PERSON_CONTACT_TYPE_ID"/>

    <property name="organizationName" type="string" column="ORGANIZATION_NAME" length="35"/>

    <property name="relationship" type="string" column="CONTACT_RELATIONSHIP_TEXT" length="250"/>

    <component name="representativeName" class="gov.va.med.esr.common.model.person.Name">
      <property name="prefix" type="string" column="PREFIX" length="12"/>
      <property name="givenName" type="string" column="FIRST_NAME" length="30"/>
      <property name="middleName" type="string" column="MIDDLE_NAME" length="30"/>
      <property name="familyName" type="string" column="LAST_NAME" length="40"/>
      <property name="suffix" type="string" column="SUFFIX" length="12"/>
    </component>

    <component name="address" class="gov.va.med.esr.common.model.party.Address">
      <property name="internalLine1" type="string" column="ADDRESS_LINE1" length="40"/>
      <property name="internalLine2" type="string" column="ADDRESS_LINE2" length="40"/>
      <property name="internalLine3" type="string" column="ADDRESS_LINE3" length="40"/>
      <property name="internalCity" type="string" column="CITY" length="50"/>
      <property name="internalCounty" type="string" column="COUNTY_CODE" length="50"/>
      <property name="internalState" type="string" column="STATE_CODE" length="50"/>
      <property name="internalZipCode" type="string" column="ZIP_CODE" length="5"/>
      <property name="internalZipPlus4" type="string" column="ZIP_PLUS_4" length="4"/>
      <property name="internalPostalCode" type="string" column="POSTAL_CODE" length="20"/>
      <property name="internalProvince" type="string" column="PROVINCE_CODE" length="20"/>
      <property name="internalCountry" type="string" column="COUNTRY_CODE" length="50"/>

      <many-to-one
          name="countryObject"
          property-ref="code"
          class="gov.va.med.esr.common.model.lookup.Country"
          cascade="none"
          insert="false"
          update="false">
        <column name="COUNTRY_CODE"/>
      </many-to-one>
    </component>

    <property name="primaryPhone" type="string" column="HOME_PHONE" length="30"/>
    <property name="alternatePhone" type="string" column="WORK_PHONE" length="30"/>

    <property name="deactivationDate" type="java.util.Date" column="DEACTIVATION_DATE"/>
    <property name="primaryPhoneChangeDate" type="java.util.Date" column="HOME_PHONE_UPDATE_DATE"/>

    <property name="alternatePhoneChangeDate" type="java.util.Date"
              column="WORK_PHONE_UPDATE_DATE"/>

    <property name="lastUpdateDate" type="timestamp" column="CONTACT_DATA_LAST_EDIT_DATE"/>

    <property name="createdOn" column="RECORD_CREATED_DATE" type="timestamp" not-null="true"
              update="false"/>
    <property name="modifiedOn" column="RECORD_MODIFIED_DATE" type="timestamp" not-null="true"/>
    <property name="createdBy" column="RECORD_CREATED_BY" update="false"
              type="gov.va.med.fw.persistent.hibernate.AuditUserType"/>
    <property name="modifiedBy" column="RECORD_MODIFIED_BY"
              type="gov.va.med.fw.persistent.hibernate.AuditUserType"/>
  </class>
</hibernate-mapping>
