-->
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.  [ 6 posts ] 
Author Message
 Post subject: fetching data from a table which is populated externally
PostPosted: Wed Oct 10, 2007 2:28 am 
Newbie

Joined: Wed Oct 10, 2007 2:08 am
Posts: 5
Hi Folks,

I need your help regarding hibernate.

I have a form in my jsp page. There are two sections in the form which should be generated dynamically. These 2 sections are only strings. I have a table which contains these strings in 2 columns. This table is only used for fetching purpose, no update,delete,insert. This table will be populated externally by some admin.
The requirement is :
Based on the customer the user belongs an appropriate form description and form declaration(the 2 strings and columns i talked about earlier) will be displayed on the form page.

I need to issue the following DB query in order to fetch the data from the table :

Code:
select form.form_description,form.form_declaration from Organisation org,Subscriber sub,MR_Form_Master form,person_master per
where org.CUST_ID = sub.CUST_ID
and sub.PERSON_ID = per.PERSON_ID
and org.FORM_ID = form.FORM_ID
and per.person_id = 28


There are 4 tables involved in this query in order to fetch the data. The strings belong to MR_Form_Master table.

I have created a MRFormMaster pojo and corresponding hbm file. Following are the codes :

Code:
public class MRFormMaster {
   
   private Integer formId;
   private String formName;
   private String isActive;
   private String formDescription;
   private String formDeclaration;
   private String createdBy;
   private Date createdDate;
   private String modifiedBy;
   private Date modifiedDate;

......corresponding getters/setters


Code:
<hibernate-mapping>
<class
    name="com.nationwide.nsbu.bh.model.MRFormMaster"
    table="MR_FORM_MASTER"
>

    <id
        name="formId"
        type="java.lang.Integer"
        column="FORM_ID"
    >
       <!--  <generator class="increment" /> -->
        <generator class="sequence">
    <param name="sequence">MRFM_FORM_ID</param>
</generator>
       
       
    </id>

    <property
        name="formName"
        type="java.lang.String"
        column="FORM_NAME"
        length="100"
    />
    <property
        name="isActive"
        type="java.lang.String"
        column="IS_ACTIVE"
        length="1"
    />
   
    <property
        name="formDescription"
        type="java.lang.String"
        column="FORM_DESCRIPTION"
        length="400"
    />
   
    <property
        name="formDeclaration"
        type="java.lang.String"
        column="FORM_DECLARATION"
        length="400"
    />
    <property
        name="createdBy"
        type="java.lang.String"
        column="CREATED_BY"
        length="101"
    />
    <property
        name="createdDate"
        type="java.sql.Timestamp"
        column="CREATED_DATE"
        length="7"
    />
    <property
        name="modifiedBy"
        type="java.lang.String"
        column="MODIFIED_BY"
        length="101"
    />
    <property
        name="modifiedDate"
        type="java.sql.Timestamp"
        column="MODIFIED_DATE"
        length="7"
    />


</class>
</hibernate-mapping>


How do I write my dao code in order to fetch the data and display it on the form page? I have all the POJOs and hbm files for the other tables i.e Subscriber,Person_Master,Organization. When I am trying to query in hibernate I am getting an object array, not an MRFormMaster instance. As a result of wghich I cannot get the value of formDescription and formDeclaration properties.

Plz help me out. Thanks in advance.

Saurav


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 3:19 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
I think you are getting an object array because you are specifying fields in your select statement, i.e.

select form.form_description,form.form_declaration

I think you will get the form object if you select form itself like

Select form from .....


Top
 Profile  
 
 Post subject: multiple columns are fetching
PostPosted: Wed Oct 10, 2007 4:07 am 
Newbie

Joined: Wed Oct 10, 2007 2:08 am
Posts: 5
I have tried this out but didn't work. If I issue the following query thru hibernate then all columns from all tables will be fetched and the properties won't match the properties in MRFormMaster pojo. I wont be able to typecast the resultSet object to the MRFormMaster pojo :

Code:
from MRFormMaster fm, Oraganization org, PersonMaster pm," +
" Subscriber sub where where org.custId = sub.custId and sub.personId = pm.personId" +"and org.formId = fm.formId and pm.personId ="+personId


Top
 Profile  
 
 Post subject: Multiple objects as resultSet
PostPosted: Wed Oct 10, 2007 4:20 am 
Newbie

Joined: Wed Oct 10, 2007 2:08 am
Posts: 5
Queries may return multiple objects and/or properties as an array of type Object[]. After getting the Object[] how will I know which element in the array corresponds to which POJO?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 4:34 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
I think this query would return MRFormMaster objects only

Code:
Select fm from MRFormMaster fm, Oraganization org, PersonMaster pm," +
" Subscriber sub where where org.custId = sub.custId and sub.personId = pm.personId" +"and org.formId = fm.formId and pm.personId ="+personId


Top
 Profile  
 
 Post subject: ClassCastException after casting resultset
PostPosted: Wed Oct 10, 2007 8:29 am 
Newbie

Joined: Wed Oct 10, 2007 2:08 am
Posts: 5
In the log file it is showing that the MRFormMaster is getting fetched with all the column values but when I am trying to cast the resultset to MRForm pojo i am getting a ClassCastException. Here is my code in the DAO :

Code:
Iterator formInfoList = hibernateOperations.iterate("select fm from MRFormMaster fm, Oraganisation org, PersonMaster pm," +
             " Subscriber sub where org.custId = sub.oraganisation.custId and sub.personMaster.personId = pm.personId" +
                " and org.mrFormMaster.formId = fm.formId and pm.personId ="+personId );
       while ( formInfoList.hasNext() ) {
           Object[] form = (Object[]) formInfoList.next();
            mrFormMaster = (MRFormMaster)form[0];
       }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.