<?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" default-cascade="all">
	<class name="gov.va.med.cds.audit.ClientMapping" table="CLIENT_MAPPING" lazy="false">
		<id name="clientMappingId" type="java.lang.Long">
			<column name="client_Mapping_Id" />
			<generator class="sequence">
				<param name="sequence">client_mapping_SEQ_ID</param>
			</generator>
		</id>

		<property name="name" column="CLIENT_NAME" />
		<property name="shortName" column="CLIENT_SHORT_NAME" />
		<property name="domainEntryPoints" column="DOMAIN_ENTRY_POINTS" />
		<property name="domains" column="DOMAINS" />

		<many-to-one name="filterIdWrapper" class="gov.va.med.cds.audit.FilterIdWrapper" column="filter_name_Id" unique="true" />

		<many-to-one name="templateIdWrapper" class="gov.va.med.cds.audit.TemplateIdWrapper" column="template_name_Id" unique="true" />
	</class>

<!--     <class name="gov.va.med.cds.audit.FilterIdWrapper" table="FILTER_NAME" lazy="false" > -->
<!--         <id type="java.lang.Long" name="id" > -->
<!--             <column name="FILTER_NAME_ID" /> -->
<!--  			<generator class="sequence"> -->
<!-- 				<param name="sequence">filter_name_seq_id</param> -->
<!-- 			</generator> -->
<!--         </id> -->

<!-- 		<property name="filterId" column="FILTER_NAME_IDENTIFIER" type="java.lang.String" /> -->
<!-- 	</class> -->
	
	<!-- The Client Name is a free text field and might not be consistent used by the client. -->
	<query name="cds.clientmapping.filter.template.clientname">
        <![CDATA[
        from ClientMapping cm
        left join fetch cm.filterIdWrapper f
        left join fetch cm.templateIdWrapper t
        where (t.id = :templateId and f.id = :filterId and (lower(cm.name) = lower(:clientName)) ) 
        ]]>
	</query>

	<query name="cds.clientmapping.filter.template">
        <![CDATA[
        from ClientMapping cm
        left join fetch cm.filterIdWrapper f
        left join fetch cm.templateIdWrapper t
        where t.id = :templateId and f.id = :filterId
        ]]>
	</query>

</hibernate-mapping>
