Hi,
Hibernate version:3.0
mapping document : CertCartons.hbm.xml
I am not able to retrieve the values for the many-to-one relationships
where i am able to retrieve values for one-to-one relationships..
Please do check my code & .hbm.xml file:-
List alReasons = hibSession.createCriteria(CertCartonsDTO.class,"carton") .createAlias("certPallets","cp") //association path with alias .setProjection(Projections.projectionList() .add(Projections.property("carton.ccCartonNo"),"ccCartonNo")// working well .add(Projections.property("cp.cpPalletNo"),"certPallets.cpPalletNo")) // Not working for many-to-one .add(Property.forName("carton.ccCartonNo").eq(new String("CA89374238"))) .setResultTransformer(new AliasToBeanResultTransformer(CertCartonsDTO.class)).list(); System.out.println("The list size is what???"+alReasons.size()); for(int i=0;i<alReasons.size();i++){ oCertCartonsDTO=(CertCartonsDTO)alReasons.get(i); System.out.println("The oCertCartonsDTO.getCcCartonNo() is what???"+oCertCartonsDTO.getCcCartonNo()); //getting the value System.out.println("The oCertCartonsDTO.getCertPallets().getCpPalletNo()is what???"+oCertCartonsDTO.getCertPallets().getCpPalletNo()); //null }
CertCartonsDTO.hbm.xml:-
<?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> <!-- Auto-generated mapping file from the hibernate.org cfg2hbm engine --> <class name="com.sitx.common.certinventory.dto.CertCartonsDTO" table="CERT_CARTONS" > <id name="ccCartonNo" type="string"> <column name="CC_CARTON_NO" length="14" /> <generator class="assigned" /> </id> <many-to-one name="certPallets" class="com.sitx.common.certinventory.dto.CertPalletsDTO" fetch="select"> <column name="CC_PALLET_NO" length="14" /> </many-to-one> <many-to-one name="RLocationTypes" class="com.sitx.common.certinventory.dto.RLocationTypesDTO" fetch="select"> <column name="CC_LOCATION_FROM" length="9" /> </many-to-one> <many-to-one name="RLocationTypes_1" class="com.sitx.common.certinventory.dto.RLocationTypesDTO" fetch="select"> <column name="CC_LOCATION_TO" length="9" /> </many-to-one> <many-to-one name="RStateReasonCodes" class="com.sitx.common.certinventory.dto.RStateReasonCodesDTO" fetch="select"> <column name="CC_STATUS_CODE" length="3" /> </many-to-one> <many-to-one name="RExceptions" class="com.sitx.common.certinventory.dto.RExceptionsDTO" fetch="select"> <column name="CC_EXCEPTION_CODE" precision="22" scale="0" /> </many-to-one> <many-to-one name="RCertTypes" class="com.sitx.common.certinventory.dto.RCertTypesDTO" fetch="select"> <column name="CC_CERT_TYPE" length="3" /> </many-to-one> <many-to-one name="RStateReasonCodes_1" class="com.sitx.common.certinventory.dto.RStateReasonCodesDTO" fetch="select"> <column name="CC_REASON_CODE" length="3" /> </many-to-one> <property name="ccRangeStartNo" type="big_decimal"> <column name="CC_RANGE_START_NO" precision="22" scale="0" /> </property> <property name="ccRangeEndNo" type="big_decimal"> <column name="CC_RANGE_END_NO" precision="22" scale="0" /> </property> <property name="ccCreateLogin" type="string"> <column name="CC_CREATE_LOGIN" length="20" /> </property> <property name="ccCreateDt" type="date"> <column name="CC_CREATE_DT" length="7" /> </property> <property name="ccUpdateLogin" type="string"> <column name="CC_UPDATE_LOGIN" length="20" /> </property> <property name="ccUpdateDt" type="date"> <column name="CC_UPDATE_DT" length="7" /> </property> <property name="ccComment" type="string"> <column name="CC_COMMENT" length="80" /> </property> <property name="ccUnfolded" type="string"> <column name="CC_UNFOLDED" precision="22" scale="0" /> </property> <set name="certBookses" inverse="true"> <key> <column name="CB_CARTON_NO" length="14" /> </key> <one-to-many class="com.sitx.common.certinventory.dto.CertBooksDTO" /> </set> <set name="certCartonsTrnses" inverse="true"> <key> <column name="CTT_CARTON_NO" length="14" /> </key> <one-to-many class="com.sitx.common.certinventory.dto.CertCartonsTrnsDTO" /> </set> <set name="certBooksTrnses" inverse="true"> <key> <column name="CBT_CARTON_NO" length="14" /> </key> <one-to-many class="com.sitx.common.certinventory.dto.CertBooksTrnsDTO" /> </set> </class> </hibernate-mapping>
I have also tried fetch="join" in .hbm.xml still iam not able to retrieve the value for many-to-one.
Where the association path is correct(cp.cpPalletNo) where string after that to retrieve the value is : certPallets.cpPalletNo(which is CertCartonsDTO.certPallets.cpPalletNo) which is the one that is actually
giving the problem . But the string mapping seems to be right. The exception is as follows:-
Hibernate: select this_.CC_CARTON_NO as y0_, cp1_.CP_PALLET_NO as y1_ from CERT_CARTONS this_, CERT_PALLETS cp1_ where this_.CC_PALLET_NO=cp1_.CP_PALLET_NO and this_.CC_CARTON_NO=? org.hibernate.PropertyAccessException: could not find a property getter of com.sitx.common.certinventory.dto.CertCartonsDTO.certPallets.cpPalletNo at org.hibernate.property.ChainedPropertyAccessor.getSetter(Ljava.lang.C lass;Ljava.lang.String;)Lorg.hibernate.property.Setter;(ChainedPropertyAccessor. java:49) at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple([ Ljava.lang.Object;[Ljava.lang.String;)Ljava.lang.Object;(AliasToBeanResultTransf ormer.java:57) at org.hibernate.loader.criteria.CriteriaLoader.getResultColumnOrRow([Lj ava.lang.Object;Ljava.sql.ResultSet;Lorg.hibernate.engine.SessionImplementor;)Lj ava.lang.Object;(CriteriaLoader.java:115) at org.hibernate.loader.Loader.doQuery(Lorg.hibernate.engine.SessionImpl ementor;Lorg.hibernate.engine.QueryParameters;Z)Ljava.util.List;(Optimized Metho d) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Lo rg.hibernate.engine.SessionImplementor;Lorg.hibernate.engine.QueryParameters;Z)L java.util.List;(Loader.java:223) at org.hibernate.loader.Loader.doList(Lorg.hibernate.engine.SessionImple mentor;Lorg.hibernate.engine.QueryParameters;)Ljava.util.List;(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Lorg.hibernate.engin e.SessionImplementor;Lorg.hibernate.engine.QueryParameters;)Ljava.util.List;(Loa der.java:2026) at org.hibernate.loader.Loader.list(Lorg.hibernate.engine.SessionImpleme ntor;Lorg.hibernate.engine.QueryParameters;Ljava.util.Set;[Lorg.hibernate.type.T ype;)Ljava.util.List;(Loader.java:2021) at org.hibernate.loader.criteria.CriteriaLoader.list(Lorg.hibernate.engi ne.SessionImplementor;)Ljava.util.List;(CriteriaLoader.java:94)
Please do provide a solution for this..
Thanks,
HibCrazyLoverr
[/u]
|