-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Hibernate with Projections not returning the values???
PostPosted: Thu Feb 02, 2006 2:14 am 
Newbie

Joined: Wed Feb 01, 2006 12:45 pm
Posts: 18
Hi,

The hibernate version is: 3.0
Mapping Document is: RStateReasonCodesDTO
Database Version is : 9.0

I have the following query in Hibernate projections which is actually returning a list size 5.
Which is right, when i try to get the value from the DTO (Which is not null) but the values i am getting from it using getters are null.
What is the problem here???? This is my piece of code:-


public List findAllReasons() {
System.out.println("Inside the findAllReasons Method");
List alReasons = null;
RStateReasonCodesDTO oRStateReasonCodesDTO=null;
Session hibSession = HibernateUtil.getSession();
alReasons = hibSession.createCriteria(RStateReasonCodesDTO.class,"reason")
.setProjection( Projections.projectionList().add( Projections.property("reason.RType")))
.add(Property.forName("reason.RType").eq(new String("state")))
.setResultTransformer(new AliasToBeanResultTransformer(RStateReasonCodesDTO.class)).list();
System.out.println("The list size is what???"+alReasons.size());// size is 5
for(int i=0;i<alReasons.size();i++){
oRStateReasonCodesDTO=(RStateReasonCodesDTO)alReasons.get(i);
System.out.println("The oRStateReasonCodesDTO is null or not???"+oRStateReasonCodesDTO); // Not null
System.out.println("The oRStateReasonCodesDTO.getRDesc() is what???"+oRStateReasonCodesDTO.getRDesc()); // null
System.out.println("The oRStateReasonCodesDTO.getRCode() is what???"+oRStateReasonCodesDTO.getRCode()); // null
}
return alReasons;
}


This is my 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.RStateReasonCodesDTO" table="R_STATE_REASON_CODES" >
<id name="RCode" type="string">
<column name="R_CODE" length="3" />
<generator class="assigned" />
</id>
<many-to-one name="RStateReasonCodes" class="com.sitx.common.certinventory.dto.RStateReasonCodesDTO" update="false" insert="false" fetch="select">
<column name="R_CODE" length="3" not-null="true" unique="true" />
</many-to-one>
<property name="RType" type="string">
<column name="R_TYPE" length="20" />
</property>
<property name="RDesc" type="string">
<column name="R_DESC" length="50" />
</property>
<property name="RCreateLogin" type="string">
<column name="R_CREATE_LOGIN" length="20" />
</property>
<property name="RCreateDt" type="date">
<column name="R_CREATE_DT" length="7" />
</property>
<property name="RUpdateLogin" type="string">
<column name="R_UPDATE_LOGIN" length="20" />
</property>
<property name="RUpdateDt" type="date">
<column name="R_UPDATE_DT" length="7" />
</property>
<property name="RParentCode" type="string">
<column name="R_PARENT_CODE" length="18" />
</property>
<set name="certCertificateses" inverse="true">
<key>
<column name="CT_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCertificatesDTO" />
</set>
<set name="certCertificateses_1" inverse="true">
<key>
<column name="CT_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCertificatesDTO" />
</set>
<set name="certPalletses" inverse="true">
<key>
<column name="CP_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertPalletsDTO" />
</set>
<set name="certBooksTrnses" inverse="true">
<key>
<column name="CBT_CERT_TYPE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertBooksTrnsDTO" />
</set>
<set name="certCertificatesTrnses" inverse="true">
<key>
<column name="CRN_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCertificatesTrnsDTO" />
</set>
<set name="certPalletses_1" inverse="true">
<key>
<column name="CP_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertPalletsDTO" />
</set>
<set name="certCartonsTrnses" inverse="true">
<key>
<column name="CTT_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCartonsTrnsDTO" />
</set>
<set name="certPalletsTrnses" inverse="true">
<key>
<column name="CPT_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertPalletsTrnsDTO" />
</set>
<set name="RStateReasonCodeses" inverse="true">
<key>
<column name="R_CODE" length="3" not-null="true" unique="true" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.RStateReasonCodesDTO" />
</set>
<set name="certCartonses" inverse="true">
<key>
<column name="CC_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCartonsDTO" />
</set>
<set name="certPalletsTrnses_1" inverse="true">
<key>
<column name="CPT_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertPalletsTrnsDTO" />
</set>
<set name="certBooksTrnses_1" inverse="true">
<key>
<column name="CBT_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertBooksTrnsDTO" />
</set>
<set name="certCartonsTrnses_1" inverse="true">
<key>
<column name="CTT_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCartonsTrnsDTO" />
</set>
<set name="certBooksTrnses_2" inverse="true">
<key>
<column name="CBT_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertBooksTrnsDTO" />
</set>
<set name="certBookses" inverse="true">
<key>
<column name="CB_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertBooksDTO" />
</set>
<set name="certCartonses_1" inverse="true">
<key>
<column name="CC_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCartonsDTO" />
</set>
<set name="certCertificatesTrnses_1" inverse="true">
<key>
<column name="CRN_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCertificatesTrnsDTO" />
</set>
<set name="certExchanges" inverse="true">
<key>
<column name="CX_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertExchangeDTO" />
</set>
<set name="certBookses_1" inverse="true">
<key>
<column name="CB_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertBooksDTO" />
</set>
</class>
</hibernate-mapping>


Please do check it and provide a solution for this. Since it is quite
urgent..

Thanks,
HibernateCrazyLoverr


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 7:37 am 
Newbie

Joined: Wed Feb 01, 2006 12:45 pm
Posts: 18
Still there is no replies...Please do provide some solution on it..

Thanks,
HibernateCrazyLoverr


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 8:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i were planning on just putting the standard response here, but then i discovered what you are actually doing ;)

Lets take it step by step...

You create a criteria rooted in your DTO:

Code:
alReasons = hibSession.createCriteria(RStateReasonCodesDTO.class,"reason")


You tell hibernate to perform a projection so only the reason.RType is selected.

Code:
.setProjection( Projections.projectionList().add( Projections.property("reason.RType")))


Add a criterion so only get data back where RType is equal to "state"

Code:
.add(Property.forName("reason.RType").eq(new String("state")))


Set the resulttransformer to take the data returned per alias and transform it into a DTO bean.

Code:
.setResultTransformer(new AliasToBeanResultTransformer(RStateReasonCodesDTO.class)).list();


So now that you have done that why do you think that any property besides "RType" will be set on your DTO when you have explicitly told hibernate to only fetch that attribute ?

Think about that, and if you do not the next time i'll just insert the standard response ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 9:07 am 
Newbie

Joined: Wed Feb 01, 2006 12:45 pm
Posts: 18
Hi Max,

Thank u for ur comments... But max, i have made some changes in the
code but still i am not able to get the RType value . I am getting the list size as 5. So, obviously the query is getting executed.Where the DTO is not null ..How come the Rtype value is null when i try to retrieve it?
That is my question.


Updated Code:-

alReasons = hibSession.createCriteria(RStateReasonCodesDTO.class,"reason")
.setProjection( Projections.projectionList().add( Projections.property("reason.RType")))
.add(Property.forName("reason.RType").eq(new String("state")))
.setResultTransformer(new AliasToBeanResultTransformer(RStateReasonCodesDTO.class)).list();
System.out.println("The list size is what???"+alReasons.size());// size is 5
for(int i=0;i<alReasons.size();i++){
oRStateReasonCodesDTO=(RStateReasonCodesDTO)alReasons.get(i);
System.out.println("The oRStateReasonCodesDTO is null or not???"+oRStateReasonCodesDTO);//Not null
System.out.println("The oRStateReasonCodesDTO.getRType() is what???"+oRStateReasonCodesDTO.getRType()); // null


Can u please check it..For ur reference i am using the following .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.RStateReasonCodesDTO" table="R_STATE_REASON_CODES" >
<id name="RCode" type="java.lang.String">
<column name="R_CODE" length="3" />
<generator class="assigned" />
</id>
<many-to-one name="RStateReasonCodes" class="com.sitx.common.certinventory.dto.RStateReasonCodesDTO" update="false" insert="false" fetch="select">
<column name="R_CODE" length="3" not-null="true" unique="true" />
</many-to-one>
<property name="RType" type="java.lang.String">
<column name="R_TYPE" length="20" />
</property>
<property name="RDesc" type="java.lang.String">
<column name="R_DESC" length="50" />
</property>
<property name="RCreateLogin" type="java.lang.String">
<column name="R_CREATE_LOGIN" length="20" />
</property>
<property name="RCreateDt" type="java.util.Date">
<column name="R_CREATE_DT" length="7" />
</property>
<property name="RUpdateLogin" type="java.lang.String">
<column name="R_UPDATE_LOGIN" length="20" />
</property>
<property name="RUpdateDt" type="java.util.Date">
<column name="R_UPDATE_DT" length="7" />
</property>
<property name="RParentCode" type="java.lang.String">
<column name="R_PARENT_CODE" length="18" />
</property>
<set name="certCertificateses" inverse="true">
<key>
<column name="CT_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCertificatesDTO" />
</set>
<set name="certCertificateses_1" inverse="true">
<key>
<column name="CT_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCertificatesDTO" />
</set>
<set name="certPalletses" inverse="true">
<key>
<column name="CP_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertPalletsDTO" />
</set>
<set name="certBooksTrnses" inverse="true">
<key>
<column name="CBT_CERT_TYPE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertBooksTrnsDTO" />
</set>
<set name="certCertificatesTrnses" inverse="true">
<key>
<column name="CRN_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCertificatesTrnsDTO" />
</set>
<set name="certPalletses_1" inverse="true">
<key>
<column name="CP_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertPalletsDTO" />
</set>
<set name="certCartonsTrnses" inverse="true">
<key>
<column name="CTT_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCartonsTrnsDTO" />
</set>
<set name="certPalletsTrnses" inverse="true">
<key>
<column name="CPT_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertPalletsTrnsDTO" />
</set>
<set name="RStateReasonCodeses" inverse="true">
<key>
<column name="R_CODE" length="3" not-null="true" unique="true" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.RStateReasonCodesDTO" />
</set>
<set name="certCartonses" inverse="true">
<key>
<column name="CC_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCartonsDTO" />
</set>
<set name="certPalletsTrnses_1" inverse="true">
<key>
<column name="CPT_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertPalletsTrnsDTO" />
</set>
<set name="certBooksTrnses_1" inverse="true">
<key>
<column name="CBT_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertBooksTrnsDTO" />
</set>
<set name="certCartonsTrnses_1" inverse="true">
<key>
<column name="CTT_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCartonsTrnsDTO" />
</set>
<set name="certBooksTrnses_2" inverse="true">
<key>
<column name="CBT_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertBooksTrnsDTO" />
</set>
<set name="certBookses" inverse="true">
<key>
<column name="CB_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertBooksDTO" />
</set>
<set name="certCartonses_1" inverse="true">
<key>
<column name="CC_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCartonsDTO" />
</set>
<set name="certCertificatesTrnses_1" inverse="true">
<key>
<column name="CRN_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertCertificatesTrnsDTO" />
</set>
<set name="certExchanges" inverse="true">
<key>
<column name="CX_REASON_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertExchangeDTO" />
</set>
<set name="certBookses_1" inverse="true">
<key>
<column name="CB_STATUS_CODE" length="3" />
</key>
<one-to-many class="com.sitx.common.certinventory.dto.CertBooksDTO" />
</set>
</class>
</hibernate-mapping>

You can help me...Waiting for ur reply...


Thanks,
HibernateCrazyLoverr


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 11:05 am 
Newbie

Joined: Wed Feb 01, 2006 12:45 pm
Posts: 18
Since,it is urgent and blocking few issues...Any one have any idea about this??? Please do reply ASAP..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If your posting (or a question you are referring to) was not answered by anybody, the possible reasons are:

- http://www.hibernate.org/ForumMailingli ... AskForHelp
- You did not submit enough information
- Nobody knows the answer or has the free time to answer

What you can do now:

- Do the things listed in After Posting
- Add missing and/or more information
- Consider commercial support for guaranteed expert response times

This is a high-traffic forum run by volunteers with hundreds of postings made every day. The community works because people try to help others in their free time. Nobody is paid for this service or has to pay.

You should not expect a timely response and you should not rely on a public community forum for critical cases.

All community members should respect the rules of this forum and treat others like they would prefer to be treated.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 6:39 am 
Beginner
Beginner

Joined: Wed Apr 26, 2006 4:40 am
Posts: 24
max wrote:
i were planning on just putting the standard response here,
You tell hibernate to perform a projection so only the reason.RType is selected.

Is there any way to tell hibernate to fetch all attributes of a class in a Projection query besides putting them in the ProjectionList one by one?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 10:28 am 
Newbie

Joined: Thu May 11, 2006 10:19 am
Posts: 1
You wrote in line 2
.setProjection( Projections.projectionList().add( Projections.property("reason.RType")))

You have to write the property and the correct alias..

.add(Projections.property("reason.RType"),"your alias");

The point is that you have to tell the resulttransformer where in your bean it should put your values. (i think)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.