Dear hibernate developers,
I need to select some values from the VOR table. I have the vognum in hand which is the primary key in VOG table which refernced vognum in VOR table. Please help me how to write the one to many mapping and how to select the values after mapping is done.
The normal SQL query looks like this.
SELECT
vor.MDLVAR,
vor.KLRKOD,
vor.MRKKOD,
vor.VORLDATVA,
vor.VORLDATTM,
vor.VORANTBST,
vor.VORANTGEL,
vor.VORANTNOG,
vor.VORPRS,
FROM VOR vor,VOG vog
AND vor.vognum = vog.vognum
AND vog.vognum= "+vognum
Below I'm giving all the related files
Hibernate version:3.1
Mapping documents:
[size=18]The Vog.hbm.xml file[/size]
<hibernate-mapping>
<class name="com.DAO.orders.Vog" table="vog" catalog="pao">
<id name="vognum" type="java.lang.Integer">
<column name="VOGNUM" />
<generator class="native" />
</id>
<property name="adrnum" type="java.lang.Integer">
<column name="ADRNUM" />
</property>
<property name="ehdkod" type="java.lang.String">
<column name="EHDKOD" length="6" />
</property>
<property name="mgpnum" type="java.lang.Integer">
<column name="MGPNUM" />
</property>
<property name="prsnum" type="java.lang.Integer">
<column name="PRSNUM" />
</property>
<property name="radnum" type="java.lang.Integer">
<column name="RADNUM" />
</property>
<property name="stanum" type="java.lang.Short">
<column name="STANUM" />
</property>
<property name="vogprinted" type="java.lang.Short">
<column name="VOGPRINTED" />
</property>
<property name="vogvog" type="java.lang.Integer">
<column name="VOGVOG" not-null="true" />
</property>
<property name="vorcredat" type="java.util.Date">
<column name="VORCREDAT" length="10" />
</property>
<property name="vorfktvpk" type="java.lang.Integer">
<column name="VORFKTVPK" />
</property>
<property name="vorgsl" type="java.lang.Short">
<column name="VORGSL" />
</property>
<property name="vorinfotxt" type="java.lang.String">
<column name="VORINFOTXT" length="160" />
</property>
<property name="vorinkver" type="java.lang.Short">
<column name="VORINKVER" />
</property>
<property name="vorkrt" type="java.lang.Double">
<column name="VORKRT" precision="4" />
</property>
<property name="vorkrtfkt" type="java.lang.Double">
<column name="VORKRTFKT" precision="4" />
</property>
<property name="vorkstvra" type="java.lang.Short">
<column name="VORKSTVRA" />
</property>
<property name="vorldattm" type="java.util.Date">
<column name="VORLDATTM" length="10" />
</property>
<property name="vorldatva" type="java.util.Date">
<column name="VORLDATVA" length="10" />
</property>
<property name="vorordbev" type="java.lang.Short">
<column name="VORORDBEV" />
</property>
<property name="vororddat" type="java.util.Date">
<column name="VORORDDAT" length="10" />
</property>
<property name="vorordkla" type="java.lang.String">
<column name="VORORDKLA" length="30" />
</property>
<property name="vorpri" type="java.lang.Short">
<column name="VORPRI" />
</property>
<property name="vorprskst" type="java.lang.Double">
<column name="VORPRSKST" precision="12" />
</property>
<property name="vorres" type="java.lang.Short">
<column name="VORRES" />
</property>
<property name="vtynum" type="java.lang.Integer">
<column name="VTYNUM" />
</property>
<property name="vvvnum" type="java.lang.Integer">
<column name="VVVNUM" />
</property>
<property name="vzwnum" type="java.lang.Integer">
<column name="VZWNUM" />
</property>
<property name="wmanum" type="java.lang.Integer">
<column name="WMANUM" not-null="true" />
</property>
<many-to-one name="bkdkod" class="com.DAO.orders.Bkd" column="bkdkod">
</many-to-one>
<many-to-one name="klanum" class="com.DAO.orders.Kla" property-ref="klanum">
</many-to-one>
<many-to-one name="vernum" class="com.DAO.orders.Ver" property-ref="vernum">
</many-to-one>
<many-to-one name="magnum" class="com.DAO.orders.Mag" column="MAGNUM">
</many-to-one>
<many-to-one name="seikod" class="com.DAO.orders.Sei" column="SEIKOD">
</many-to-one>
<many-to-one name="valnum" class="com.DAO.orders.Val" property-ref="valnum">
</many-to-one>
<many-to-one name="leknum" class="com.DAO.orders.Lek" column="leknum">
</many-to-one>
<many-to-one name="debnum" class="com.DAO.orders.Deb" property-ref="debnum">
</many-to-one>
<many-to-one name="expnum" class="com.DAO.orders.Exp" property-ref="expnum">
</many-to-one>
<many-to-one name="debnum2" class="com.DAO.orders.Deb" property-ref="debnum">
</many-to-one>
<many-to-one name="vosnum" class="com.DAO.orders.Vos" property-ref="vosnum">
</many-to-one>
</class>
</hibernate-mapping>
------------------------------------------------------------------------------------
[size=18]The Vor.hbm.xml file[/size]
-------------------------------------------------------------------------------------
<?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">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.DAO.orders.Vor" table="vor" catalog="pao">
<id name="vornum" type="java.lang.Integer">
<column name="VORNUM" />
<generator class="native" />
</id>
<property name="adrnum" type="java.lang.Integer">
<column name="ADRNUM" />
</property>
<property name="bkdkod" type="java.lang.String">
<column name="BKDKOD" length="4" />
</property>
<property name="debnum" type="java.lang.Integer">
<column name="DEBNUM" />
</property>
<property name="debnum2" type="java.lang.Integer">
<column name="DEBNUM2" />
</property>
<property name="ehdkod" type="java.lang.String">
<column name="EHDKOD" length="6" />
</property>
<property name="expnum" type="java.lang.Integer">
<column name="EXPNUM" />
</property>
<property name="iornum" type="java.lang.Integer">
<column name="IORNUM" />
</property>
<property name="klanum" type="java.lang.Integer">
<column name="KLANUM" />
</property>
<property name="klcnum" type="java.lang.Integer">
<column name="KLCNUM" />
</property>
<property name="klrkod" type="java.lang.String">
<column name="KLRKOD" length="6" />
</property>
<property name="leknum" type="java.lang.Integer">
<column name="LEKNUM" />
</property>
<property name="magnum" type="java.lang.Integer">
<column name="MAGNUM" />
</property>
<property name="mdlvar" type="java.lang.String">
<column name="MDLVAR" length="2" />
</property>
<property name="mgpnum" type="java.lang.Integer">
<column name="MGPNUM" />
</property>
<property name="mklnum" type="java.lang.Integer">
<column name="MKLNUM" />
</property>
<property name="mrkkod" type="java.lang.String">
<column name="MRKKOD" length="3" />
</property>
<property name="pkkkod" type="java.lang.String">
<column name="PKKKOD" length="4" />
</property>
<property name="pokkod" type="java.lang.String">
<column name="POKKOD" length="8" />
</property>
<property name="pornum" type="java.lang.Short">
<column name="PORNUM" />
</property>
<property name="prsnum" type="java.lang.Integer">
<column name="PRSNUM" />
</property>
<property name="radnum" type="java.lang.Integer">
<column name="RADNUM" />
</property>
<property name="seikod" type="java.lang.String">
<column name="SEIKOD" length="5" />
</property>
<property name="stanum" type="java.lang.Short">
<column name="STANUM" />
</property>
<property name="uninum" type="java.lang.Integer">
<column name="UNINUM" />
</property>
<property name="valnum" type="java.lang.Integer">
<column name="VALNUM" />
</property>
<property name="vannum" type="java.lang.Integer">
<column name="VANNUM" />
</property>
<property name="vernum" type="java.lang.Integer">
<column name="VERNUM" />
</property>
<property name="vognum" type="java.lang.Integer">
<column name="VOGNUM" />
</property>
<property name="vorant" type="java.lang.Double">
<column name="VORANT" precision="13" />
</property>
<property name="vorantbst" type="java.lang.Integer">
<column name="VORANTBST" />
</property>
<property name="vorantfak" type="java.lang.Double">
<column name="VORANTFAK" precision="13" />
</property>
<property name="vorantgel" type="java.lang.Integer">
<column name="VORANTGEL" />
</property>
<property name="vorantnog" type="java.lang.Integer">
<column name="VORANTNOG" />
</property>
<property name="vorartkla" type="java.lang.String">
<column name="VORARTKLA" length="25" />
</property>
<property name="vorbdrantbstbas" type="java.lang.Double">
<column name="VORBDRANTBSTBAS" precision="13" />
</property>
<property name="vorbdrantgelbas" type="java.lang.Double">
<column name="VORBDRANTGELBAS" precision="13" />
</property>
<property name="vorbdrantnogbas" type="java.lang.Double">
<column name="VORBDRANTNOGBAS" precision="13" />
</property>
<property name="vorbdrbas" type="java.lang.Double">
<column name="VORBDRBAS" precision="13" />
</property>
<property name="vorbdrtoe" type="java.lang.Double">
<column name="VORBDRTOE" precision="14" />
</property>
<property name="vorbdrval" type="java.lang.Double">
<column name="VORBDRVAL" precision="13" />
</property>
<property name="vorbdrvra" type="java.lang.Double">
<column name="VORBDRVRA" precision="14" />
</property>
<property name="vorbevdat1" type="java.util.Date">
<column name="VORBEVDAT1" length="10" />
</property>
<property name="vorbevdat2" type="java.util.Date">
<column name="VORBEVDAT2" length="10" />
</property>
<property name="vorbgndat" type="java.util.Date">
<column name="VORBGNDAT" length="10" />
</property>
<property name="vorcaldef" type="java.lang.Short">
<column name="VORCALDEF" />
</property>
<property name="vorcomkpr" type="java.lang.Double">
<column name="VORCOMKPR" precision="12" />
</property>
<property name="vorcredat" type="java.util.Date">
<column name="VORCREDAT" length="10" />
</property>
<property name="vordir" type="java.lang.Short">
<column name="VORDIR" />
</property>
<property name="vordrv" type="java.lang.Short">
<column name="VORDRV" />
</property>
<property name="vorenddat" type="java.util.Date">
<column name="VORENDDAT" length="10" />
</property>
<property name="vorfktvpk" type="java.lang.Integer">
<column name="VORFKTVPK" />
</property>
<property name="vorgsl" type="java.lang.Short">
<column name="VORGSL" />
</property>
<property name="vorinfotxt" type="java.lang.String">
<column name="VORINFOTXT" length="160" />
</property>
<property name="vorinkver" type="java.lang.Short">
<column name="VORINKVER" />
</property>
<property name="vorkrt" type="java.lang.Double">
<column name="VORKRT" precision="4" />
</property>
<property name="vorkrtfkt" type="java.lang.Double">
<column name="VORKRTFKT" precision="4" />
</property>
<property name="vorkstvra" type="java.lang.Short">
<column name="VORKSTVRA" />
</property>
<property name="vorldattm" type="java.util.Date">
<column name="VORLDATTM" length="10" />
</property>
<property name="vorldatva" type="java.util.Date">
<column name="VORLDATVA" length="10" />
</property>
<property name="vormrg" type="java.lang.Short">
<column name="VORMRG" />
</property>
<property name="voroldnum" type="java.lang.Integer">
<column name="VOROLDNUM" />
</property>
<property name="vorordbev" type="java.lang.Short">
<column name="VORORDBEV" />
</property>
<property name="vororddat" type="java.util.Date">
<column name="VORORDDAT" length="10" />
</property>
<property name="vorordkla" type="java.lang.String">
<column name="VORORDKLA" length="30" />
</property>
<property name="vorpri" type="java.lang.Short">
<column name="VORPRI" />
</property>
<property name="vorprs" type="java.lang.Integer">
<column name="VORPRS" />
</property>
<property name="vorprsadv" type="java.lang.Double">
<column name="VORPRSADV" precision="12" />
</property>
<property name="vorprskst" type="java.lang.Double">
<column name="VORPRSKST" precision="12" />
</property>
<property name="vorprstoe" type="java.lang.Double">
<column name="VORPRSTOE" precision="4" />
</property>
<property name="vorres" type="java.lang.Short">
<column name="VORRES" />
</property>
<property name="vorsgnlst" type="java.lang.String">
<column name="VORSGNLST" length="20" />
</property>
<property name="vortotfixedant" type="java.lang.Double">
<column name="VORTOTFIXEDANT" precision="13" />
</property>
<property name="vortotunitant" type="java.lang.Double">
<column name="VORTOTUNITANT" precision="13" />
</property>
<property name="vortrndag" type="java.lang.Short">
<column name="VORTRNDAG" />
</property>
<property name="vorunitant" type="java.lang.Double">
<column name="VORUNITANT" precision="13" />
</property>
<property name="vorvvdant" type="java.lang.Integer">
<column name="VORVVDANT" />
</property>
<property name="vorvvvdat" type="java.util.Date">
<column name="VORVVVDAT" length="10" />
</property>
<property name="vorzknnam" type="java.lang.String">
<column name="VORZKNNAM" length="25" />
</property>
<property name="vosnum" type="java.lang.Short">
<column name="VOSNUM" />
</property>
<property name="vtynum" type="java.lang.Integer">
<column name="VTYNUM" />
</property>
<property name="vvdnum" type="java.lang.Integer">
<column name="VVDNUM" />
</property>
<property name="vvvnum" type="java.lang.Integer">
<column name="VVVNUM" />
</property>
<property name="vzwnum" type="java.lang.Integer">
<column name="VZWNUM" />
</property>
<property name="wmanum" type="java.lang.Integer">
<column name="WMANUM" />
</property>
<property name="wmanum2" type="java.lang.Integer">
<column name="WMANUM2" />
</property>
<many-to-one name="mdlnum" class="com.DAO.model.Mdl" unique="true" column="mdlnum">
</many-to-one>
</class>
</hibernate-mapping>
Thanks and regards,
Prasanth
|