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

	<class name="ee.ut.math.tvt2008.salessystem.domain.data.StockItem" table="STOCKITEM">
		<id name="id">
			<generator class="increment" />
		</id>
		
		<property name="name" length="50" not-null="true" />
		<property name="price" type="big_decimal"/>	
		<property name="quantity" type="int"/>
	</class>

	<class name="ee.ut.math.tvt2008.salessystem.domain.data.SoldItem" table="SOLDITEM">
		<id name="id">
			<generator class="increment" />
		</id>
	
		<property name="name" length="50" not-null="true" />
		<property name="quantity" />
		<property name="price" column="itemprice"/>	
		
		<many-to-one name="sale" column="sale_id" not-null="true"/>
		
		<many-to-one
			name="stockItem"
			column="stockitem_id"
			class="ee.ut.math.tvt2008.salessystem.domain.data.StockItem"
			fetch="join"
			lazy="false"
		/>
	</class>	
	
	<class name="ee.ut.math.tvt2008.salessystem.domain.data.Sale" table="SALE">
		<id name="id">
			<generator class="increment" />
		</id>

		<property name="sellingTime"/>
		
		<set name="soldItems" table="SOLDITEMS" inverse="true" cascade="save-update">
			<key column="sale_id" />
			<one-to-many class="ee.ut.math.tvt2008.salessystem.domain.data.SoldItem" />
		</set>
		
		<many-to-one
			name="client"
			column="client_id"
			class="ee.ut.math.tvt2008.salessystem.domain.data.Client"
			fetch="join"
			lazy="false"
			not-null="false"
		/>
	</class>
	
	<class name="ee.ut.math.tvt2008.salessystem.domain.data.Client" table="CLIENT">
		<id name="id">
			<generator class="increment" />
		</id>
		
                <property name="lastName" column="last_name" />
		<property name="firstName" column="first_name"/>
		<property name="discountPercentage" column="discount" />
		<property name="dueDate" column="due_date" />
		<many-to-one name="dueSale" column="due_sale" unique="true"/>
	</class>
	
	
</hibernate-mapping>
