<?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 default-lazy="false" default-cascade="save-update">
    <class name="gov.va.med.cds.clinicaldata.TemplateMetaData" table="TEMPLATE_SCHEMA" lazy="false">
        <id type="java.lang.Long" >
            <column name="TEMPLATE_SCHEMA_ID" />
 			<generator class="sequence">
				<param name="sequence">template_schema_seq_id</param>
			</generator>
        </id>


		<property name="templateName" column="TEMPLATE_NAME" type="java.lang.String" />
		<property name="templateId" column="TEMPLATE_ID" type="java.lang.String" />
		<property name="templateDescription" column="TEMPLATE_DESCRIPTION" type="java.lang.String" />
		<property name="testOnly" column="TEST_ONLY" type="true_false" />

		<property name="operationAsString" column="REQUEST_TYPE" type="java.lang.String" />
 
		<property name="dateAdded" column="DATE_ADDED" type="java.util.Date" />
		<property name="dateActivated" column="DATE_ACTIVATED" type="java.util.Date" />
		<property name="dateDeactivated" column="DATE_DEACTIVATED" type="java.util.Date" />
		<property name="dateDeprecated" column="DATE_DEPRECATED" type="java.util.Date" />
		<property name="dateUpdated" column="DATE_UPDATED" type="java.util.Date" />
		
		<property name="status" column="STATUS" type="java.lang.String" />

		<property name="blob" column="TEMPLATE_SCHEMA_BLOB" type="java.sql.Blob" />


		<set name="domainEntryPointWrappers" table="TEMPLATE_SCHEMA_ENTRY_POINT" >
			<key column="TEMPLATE_SCHEMA_ID" not-null="true" />
			<many-to-many column="DOMAIN_ENTRY_POINT_ID" class="gov.va.med.cds.clinicaldata.DomainEntryPointWrapper" />
        </set>

	    <set name="vhimVersionWrappers" table="TEMPLATE_SCHEMA_VHIM_VERSION" >
	        <key column="TEMPLATE_SCHEMA_ID" not-null="true" />
	        <many-to-many column="VHIM_VERSION_ID" unique="true"
	            class="gov.va.med.cds.clinicaldata.VhimVersionWrapper"/>
	    </set>

    </class>



    <query name="TemplateSchemaId">
		<![CDATA[
		from TemplateMetaData tmd
		where tmd.templateId = :templateId
      ]]>
	</query>

	
	<sql-query name="TemplateSchemaIdsByStatus">
		SELECT template_Id
  		FROM template_schema ts, vhim_version vv, template_schema_vhim_Version tsvv
 		WHERE TS.TEMPLATE_SCHEMA_ID = TSVV.TEMPLATE_SCHEMA_ID
        AND TS.STATUS = :status
	</sql-query>


    <query name="AllTemplateSchemaIds">
		<![CDATA[
		select templateId from TemplateMetaData
      ]]>
	</query>

</hibernate-mapping>
