-->
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.  [ 3 posts ] 
Author Message
 Post subject: Simple Retreating Objects with Join Association Question!
PostPosted: Fri Apr 29, 2005 10:55 am 
Newbie

Joined: Tue Jan 11, 2005 11:30 pm
Posts: 3
Hi Everyone,

I appreciate it much if someone could help me out. This is the basic simple step of retreating objects by join association. I have search through the website and forum, and also read the Hibernate in action book... but I am missing something... Please help me out. I believe in J2EE without EJB and great deal of confidence in what Hibernate can do although I am not expert in Hibernate yet.

I have attached all the information that is needed. Briefly, I have two objects Biblio and Internetmarketing which has one to many relationship.
Thus, I added InternetMarketingObjects attribute with Set type to Biblio object. And I then map it in Biblio.hbm.xml ... I know that my mapping files and the rest is fine... I have a feeling the problem rely on how I am return the objects into JSP layer... by the way, I am using Struts.

I am returning list with this query

Query query = session.createQuery("from edu.nap.rubyviews.hibernate.Biblio biblio left join fetch biblio.InternetMarketingObjects");
return query.list();


The problem is in jsp layer.. I can only display Biblio attributes... if I try to display Internetmarketing object's attribute.. I have blank screen...

Can someone let me know what I am doing wrong....

THanks in advance!

K~


Hibernate version:
2.1.7

Mapping documents:
Code:

<hibernate-mapping package="edu.nap.rubyviews.hibernate">

    <class name="Biblio" table="biblio">
      
        <id name="recordId" column="record_id" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property name="author" column="author" type="java.lang.String" />
        <property name="voidCategory" column="void_category" type="java.lang.String" />
        <property name="datasource" column="datasource" type="java.lang.String" />
        <property name="deliveryDate" column="delivery_date" type="java.util.Date" />
        <property name="embargoDate" column="embargo_date" type="java.util.Date" />
        <property name="flatIsbn" column="flat_isbn" type="java.lang.String"  not-null="true" />
        <property name="footnote" column="footnote" type="java.lang.String" />
        <property name="forSale" column="for_sale" type="java.lang.String" />
        <property name="forthcoming" column="forthcoming" type="java.lang.String" />
        <property name="indexAvail" column="index_avail" type="java.lang.String" />
        <property name="jobNo" column="job_no" type="java.lang.String" />
        <property name="limitDist" column="limit_dist" type="java.lang.String" />
        <property name="marketList" column="market_list" type="java.util.Date" />
        <property name="masterPub" column="master_pub" type="java.lang.String" />
        <property name="newBiblio" column="new" type="java.lang.String" />
        <property name="org" column="org" type="java.lang.String" />
        <property name="pageCount" column="page_count" type="java.lang.Integer" />
        <property name="pendingErrata" column="pending_errata" type="java.lang.String" />
        <property name="pod" column="pod" type="java.lang.String" />
        <property name="podNo" column="pod_no" type="java.lang.String" />
        <property name="preferForm" column="prefer_form" type="java.lang.String" />
        <property name="prepub" column="prepub" type="java.lang.String" />
        <property name="pubDate" column="pub_date" type="java.util.Date" />
        <property name="pubYear" column="pub_year" type="java.lang.String" />
        <property name="quantity" column="quantity" type="java.lang.String" />
        <property name="size" column="size" type="java.lang.String" />
        <property name="subtitle" column="subtitle" type="java.lang.String" />
        <property name="title" column="title" type="java.lang.String"  not-null="true" />
        <property name="track" column="track" type="java.lang.String"  not-null="true" />
        <property name="trade" column="trade" type="java.lang.String" />
        <property name="warning" column="warning" type="java.lang.String" />
        <property name="noShow" column="no_show" type="java.lang.String" />
        <property name="tierPrice" column="tier_price" type="java.lang.String" />
        <property name="cpjCode" column="cpj_code" type="java.lang.String" />
        <property name="relatedTitle" column="related_title" type="java.lang.String" />
        <property name="pubToWeb" column="pub_to_web" type="java.util.Date" />
        <property name="approx" column="approx" type="java.lang.String" />
        <property name="urls" column="urls" type="java.lang.String" />
        <property name="firstAppear" column="first_appear" type="java.util.Date" />
        <property name="mnemonic" column="mnemonic" type="java.lang.String" />
        <property name="webOnly" column="web_only" type="java.lang.String" />
        <property name="firstAppearRubicon" column="first_appear_rubicon" type="java.util.Date" />
        <property name="pressRelease" column="press_release" type="java.lang.String" />
        <property name="copyright" column="copyright" type="java.util.Date" />
        <property name="marketingnote" column="marketingnote" type="java.lang.String" />
        <property name="marketingNote" column="marketing_note" type="java.lang.String" />
        <property name="alphaSort" column="alpha_sort" type="java.lang.String" />
        <property name="aaupList" column="aaup_list" type="java.lang.String" />
        <property name="netlibrary" column="netlibrary" type="java.lang.String" />
        <property name="openbook" column="openbook" type="java.lang.String" />
        <property name="openbook2" column="openbook2" type="java.lang.String" />
        <property name="netlibrary2" column="netlibrary2" type="java.lang.String" />
        <property name="tempOpenbook" column="temp_openbook" type="java.lang.String" />
        <property name="nrcDivision" column="nrc_division" type="java.lang.String" />
        <property name="jobNumber" column="job_number" type="java.lang.String" />
        <property name="secondAuthor" column="second_author" type="java.lang.String" />
        <property name="testSsb" column="test_ssb" type="java.lang.String" />
        <property name="tempCheck" column="temp_check" type="java.lang.String" />
        <property name="org2" column="org2" type="java.lang.String" />
        <property name="org3" column="org3" type="java.lang.String" />
        <property name="org4" column="org4" type="java.lang.String" />
        <property name="org5" column="org5" type="java.lang.String" />
        <property name="org1" column="org1" type="java.lang.String" />
        <property name="prepubPdf" column="prepub_pdf" type="java.lang.String" />
        <property name="recordCreated" column="record_created" type="java.util.Date" />
        <property name="cat1pri" column="cat1pri" type="java.lang.String" />
        <property name="cat1sub" column="cat1sub" type="java.lang.String" />
        <property name="cat2pri" column="cat2pri" type="java.lang.String" />
        <property name="cat2sub" column="cat2sub" type="java.lang.String" />
        <property name="cat3pri" column="cat3pri" type="java.lang.String" />
        <property name="cat3sub" column="cat3sub" type="java.lang.String" />
        <property name="cat4pri" column="cat4pri" type="java.lang.String" />
        <property name="cat4sub" column="cat4sub" type="java.lang.String" />
        <property name="cat5pri" column="cat5pri" type="java.lang.String" />
        <property name="cat5sub" column="cat5sub" type="java.lang.String" />
        <property name="homepageDate" column="homepage_date" type="java.util.Date" />
        <property name="bulkPricing" column="bulk_pricing" type="java.lang.String" />
        <property name="pdfAvail" column="pdf_avail" type="java.lang.String" />
        <property name="fullPdf" column="full_pdf" type="java.lang.String" />
        <property name="chapterPdf" column="chapter_pdf" type="java.lang.String" />
        <property name="jhpPressRelease" column="jhp_press_release" type="java.lang.String" />
        <property name="permissionOnly" column="permission_only" type="java.lang.String" />
        <property name="category" column="category" type="java.lang.String" />
        <property name="hasExecSumm" column="has_exec_summ" type="java.lang.String" />
        <property name="altTitle" column="alt_title" type="java.lang.String" />
        <property name="stockCode" column="stock_code" type="java.lang.String" />
        <property name="marketRestrictions" column="market_restrictions" type="java.lang.String"  not-null="true" />
        <property name="seasonalCatalog" column="seasonal_catalog" type="java.lang.String" />
        <property name="hasCd" column="has_cd" type="java.lang.String"  not-null="true" />
        <property name="t1" column="t1" type="java.lang.String" />
        <property name="execSummChapter" column="exec_summ_chapter" type="java.lang.String" />
       
         <set name="InternetMarketingObjects" inverse="true">
          <key column="record_id" />
          <one-to-many class="Internetmarketing" />
       </set>
       
    </class>
   
</hibernate-mapping>



Code:
<hibernate-mapping package="edu.nap.rubyviews.hibernate">

    <class name="Internetmarketing" table="internetmarketing">
        <id name="internetId" column="internet_id" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property name="recordId" column="record_id" type="java.lang.Integer" />
        <property name="resource" column="resource" type="java.lang.String" />
        <property name="status" column="status" type="java.lang.String" />
        <property name="pitchDate" column="pitch_date" type="java.util.Date" />
        <property name="type" column="type" type="java.lang.String" />
        <property name="comment" column="comment" type="java.lang.String" />
        <property name="contact" column="contact" type="java.lang.String" />
        <property name="email" column="email" type="java.lang.String" />
        <property name="telephone" column="telephone" type="java.lang.String" />
        <property name="address" column="address" type="java.lang.String" />
        <property name="siteName" column="site_name" type="java.lang.String" />
       

       
    </class>
   
</hibernate-mapping>





Code between sessionFactory.openSession() and session.close():
Code:
public List getViewOneList()
   {
      /*
       * Use the ConnectionFactory to retrieve an open
       * Hibernate Session.
       *
       */
      Session session = null;

      try
      {
         session = SessionFactory.currentSession();
         /*
         * Build HQL (Hibernate Query Language) query to retrieve a list
         * of all the items currently stored by Hibernate.
          */
         
         
   
         /*
         Query q = session.createQuery(" from Biblio biblio join biblio.InternetMarketingObjects internetmarketing");
         Iterator biblios = q.list().iterator();
         while (biblios.hasNext()){
            Object[] pair = (Object[]) biblios.next();
            Biblio biblio = (Biblio)pair[0];
            Internetmarketing internetmarketing = (Internetmarketing)pair[1];
            System.err.println("Title >>:   " + biblio.getTitle());
         }
      
         */
         Query query = session.createQuery("from edu.nap.rubyviews.hibernate.Biblio biblio left join fetch biblio.InternetMarketingObjects");
               
      
         return query.list();
         
      
      }
      catch (HibernateException e)
      {
         System.err.println("Hibernate Exception" + e.getMessage());
         throw new RuntimeException(e);
      }
      /*
       * Regardless of whether the above processing resulted in an Exception
       * or proceeded normally, close the Hibernate session.  When
       * closing the session, allow for the possibility of a Hibernate
       * Exception.
       *
       */
      finally
      {
         if (session != null)
         {
            try
            {
               session.close();
            }
            catch (HibernateException e)
            {
               System.err.println("Hibernate Exception" + e.getMessage());
               throw new RuntimeException(e);
            }

         }
      }
   }

Full stack trace of any exception that occurs:

No error message... this is the problem. I have no idea what is wrong.


Name and version of the database you are using:
MySQL 4.1

The generated SQL (show_sql=true):

Hibernate: select biblio0_.record_id as record_id0_, internetma1_.internet_id as internet1_1_, biblio0_.author as author0_, biblio0_.void_category as void_cat3_0_, biblio0_.datasource as datasource0_, biblio0_.delivery_date as delivery5_0_, biblio0_.embargo_date as embargo_6_0_, biblio0_.flat_isbn as flat_isbn0_, biblio0_.footnote as footnote0_, biblio0_.for_sale as for_sale0_, biblio0_.forthcoming as forthco10_0_, biblio0_.index_avail as index_a11_0_, biblio0_.job_no as job_no0_, biblio0_.limit_dist as limit_dist0_, biblio0_.market_list as market_14_0_, biblio0_.master_pub as master_pub0_, biblio0_.new as new0_, biblio0_.org as org0_, biblio0_.page_count as page_count0_, biblio0_.pending_errata as pending19_0_, biblio0_.pod as pod0_, biblio0_.pod_no as pod_no0_, biblio0_.prefer_form as prefer_22_0_, biblio0_.prepub as prepub0_, biblio0_.pub_date as pub_date0_, biblio0_.pub_year as pub_year0_, biblio0_.quantity as quantity0_, biblio0_.size as size0_, biblio0_.subtitle as subtitle0_, biblio0_.title as title0_, biblio0_.track as track0_, biblio0_.trade as trade0_, biblio0_.warning as warning0_, biblio0_.no_show as no_show0_, biblio0_.tier_price as tier_price0_, biblio0_.cpj_code as cpj_code0_, biblio0_.related_title as related36_0_, biblio0_.pub_to_web as pub_to_web0_, biblio0_.approx as approx0_, biblio0_.urls as urls0_, biblio0_.first_appear as first_a40_0_, biblio0_.mnemonic as mnemonic0_, biblio0_.web_only as web_only0_, biblio0_.first_appear_rubicon as first_a43_0_, biblio0_.press_release as press_r44_0_, biblio0_.copyright as copyright0_, biblio0_.marketingnote as marketi46_0_, biblio0_.marketing_note as marketi47_0_, biblio0_.alpha_sort as alpha_sort0_, biblio0_.aaup_list as aaup_list0_, biblio0_.netlibrary as netlibrary0_, biblio0_.openbook as openbook0_, biblio0_.openbook2 as openbook20_, biblio0_.netlibrary2 as netlibr53_0_, biblio0_.temp_openbook as temp_op54_0_, biblio0_.nrc_division as nrc_div55_0_, biblio0_.job_number as job_number0_, biblio0_.second_author as second_57_0_, biblio0_.test_ssb as test_ssb0_, biblio0_.temp_check as temp_check0_, biblio0_.org2 as org20_, biblio0_.org3 as org30_, biblio0_.org4 as org40_, biblio0_.org5 as org50_, biblio0_.org1 as org10_, biblio0_.prepub_pdf as prepub_pdf0_, biblio0_.record_created as record_66_0_, biblio0_.cat1pri as cat1pri0_, biblio0_.cat1sub as cat1sub0_, biblio0_.cat2pri as cat2pri0_, biblio0_.cat2sub as cat2sub0_, biblio0_.cat3pri as cat3pri0_, biblio0_.cat3sub as cat3sub0_, biblio0_.cat4pri as cat4pri0_, biblio0_.cat4sub as cat4sub0_, biblio0_.cat5pri as cat5pri0_, biblio0_.cat5sub as cat5sub0_, biblio0_.homepage_date as homepag77_0_, biblio0_.bulk_pricing as bulk_pr78_0_, biblio0_.pdf_avail as pdf_avail0_, biblio0_.full_pdf as full_pdf0_, biblio0_.chapter_pdf as chapter81_0_, biblio0_.jhp_press_release as jhp_pre82_0_, biblio0_.permission_only as permiss83_0_, biblio0_.category as category0_, biblio0_.has_exec_summ as has_exe85_0_, biblio0_.alt_title as alt_title0_, biblio0_.stock_code as stock_code0_, biblio0_.market_restrictions as market_88_0_, biblio0_.seasonal_catalog as seasona89_0_, biblio0_.has_cd as has_cd0_, biblio0_.t1 as t10_, biblio0_.exec_summ_chapter as exec_su92_0_, internetma1_.record_id as record_id1_, internetma1_.resource as resource1_, internetma1_.status as status1_, internetma1_.pitch_date as pitch_date1_, internetma1_.type as type1_, internetma1_.comment as comment1_, internetma1_.contact as contact1_, internetma1_.email as email1_, internetma1_.telephone as telephone1_, internetma1_.address as address1_, internetma1_.site_name as site_name1_, internetma1_.record_id as record_id__, internetma1_.internet_id as internet1___ from biblio biblio0_ left outer join internetmarketing internetma1_ on biblio0_.record_id=internetma1_.record_id

Debug level Hibernate log excerpt:
NO Exception errors....
Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 11:05 am 
Newbie

Joined: Tue Jan 11, 2005 11:30 pm
Posts: 3
This is what I have for Biblio.java

Code:

public class Biblio
    extends AbstractBiblio
    implements Serializable
{
    /**
     * Simple constructor of Biblio instances.
     */
    public Biblio()
    {
    }

    /**
     * Constructor of Biblio instances given a simple primary key.
     * @param recordId
     */
    public Biblio(java.lang.Integer recordId)
    {
        super(recordId);
    }

    /* Add customized code below */
    private Set InternetMarketingObjects = new HashSet();
   
   
   /**
    * @return Returns the internetMarketingObjects.
    */
   public Set getInternetMarketingObjects() {
      return InternetMarketingObjects;
   }
   /**
    * @param internetMarketingObjects The internetMarketingObjects to set.
    */
   public void setInternetMarketingObjects(Set internetMarketingObjects) {
      InternetMarketingObjects = internetMarketingObjects;
   }
}




Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 11:16 am 
Newbie

Joined: Tue Jan 11, 2005 11:30 pm
Posts: 3
FYI....

I have read section 7.3 of Hibernate In Action again and again..

According to 7.3.2, the query I am using should returns all biblios and all their InternetMarketingObjects in a SINGLE SELECT...

That is true because I can see that because... show_sql= true ...

I also treid Criteria API and the same thing happen.. I think the way I am retreating the object is correct but the way I am returning to Struts jsp layer is the problem...It is not recognizing the Internetmarketing objects but only biblio objects...


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