<?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
    default-lazy="false"
    auto-import="true"
    default-access="property"
    default-cascade="all"
    package="gov.va.med.esr.common.model.comms">

	<class name="DocumentReceipt" table="DOCUMENT_RECEIPT">
        <id name="identifier" type="big_decimal" column="DOCUMENT_RECEIPT_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"/>
			
		<property name="VPIDValue" type="string" column="VETERAN_ID"/>
		<property name="receiptString" type="string" column="RECEIPT_STRING"/>
		<property name="releaseControlNumber" type="string" column="RELEASE_CONTROL_NUMBER"/>
		<property name="receiptDate" type="timestamp" column="RECEIPT_DATE"/>
		<property name="versionNumber" type="integer" column="VERSION_NUMBER"/>

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

            
		<set name="internalDocuments" lazy="false" inverse="true" cascade="all-delete-orphan">
            <key column="DOCUMENT_RECEIPT_ID" />
            <one-to-many class="gov.va.med.esr.common.model.comms.Document" />
        </set>
        
        <set name="internalHealthBenefitPlan" lazy="false" inverse="true" cascade="all-delete-orphan">
            <key column="DOCUMENT_RECEIPT_ID" />
            <one-to-many class="gov.va.med.esr.common.model.comms.HealthBenefitPlan" />
        </set>
		

		<!-- ADR required attributes -->
        <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>
	
	<query name="DocumentReceipt_Identifier">
        FROM   DocumentReceipt docs
        WHERE  docs.identifier = :identifier
    </query>
	
	<query name="DocumentReceipt_All">
        FROM   DocumentReceipt docs
        WHERE  docs.VPIDValue = :personVpid
        ORDER BY docs.versionNumber desc
    </query>
    
    
    <query name="DocumentReceipt_All_ByReceiptDate_Desc">
        FROM   DocumentReceipt docs
        WHERE  docs.VPIDValue = :personVpid
        ORDER BY docs.receiptDate desc
    </query>
    
    <query name="DocumentReceipt_Version">
        FROM   DocumentReceipt docs
        WHERE  docs.VPIDValue = :personVpid
        AND    docs.versionNumber = :versionNumber
    </query>    
    <query name="DocumentReceipt_findByReceiptString">
        FROM   DocumentReceipt docs
        WHERE  receiptString = :receiptString
    </query>  
	
		
</hibernate-mapping>
