-->
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: Mapping questions related to discriminators and joins...
PostPosted: Mon Sep 27, 2004 4:30 pm 
Regular
Regular

Joined: Thu Sep 09, 2004 6:46 pm
Posts: 96
I have a legacy (badly modelled) table structure where tables are aranged as in mapping below. My problem is as follows.

Assuming that you have identified a row in SERVICE_BENEFIT_HIERARCHY and I want to return the children of this row from the same table, then to do this, I select from SERVICE_BENEFIT_HIERARCHY joined with SERVICE_BENEFIT_CATEGORY where SERVICE_BENEFIT_CATEGORY.TYP_IND = "C" and relationship of child is like the first 2 characters of relationship of parent.

I know it's the worst possible design but I didn't design it......

So my question is... Is there a way to map this short of writing HQL in a dao accessor?

Also is there a way to put a HQL mapping in hibernate i.e something like.

Code:
<set name="serviceBenefitHierarchyChildrenSet"
   inverse="true"
   lazy="true"
   cascade="all"
>   
   <one-to-many class="ServiceBenefitHierarchy">
     <hql>
         <statement>
            SELECT b
            FROM ServiceBenefitHierarchy as h
              join h.ServiceBenefitCategorySet as s
            WHERE h.relationship like ?.substring(0,1) || "%"           
            AND s.typeInd = ?
            AND h.hierarchy = ?
            ORDER BY h.relationship
         <statement>
         <column>RELATIONSHIP<column>
         <value type="string">C</value>
         <column>HIERARCHY_ID</column>
     </hql>
   </one-to-many>
</set>



This would be very powerful functionality.

Of course java substring would have to be implemented since I don't believe this functionality exists.

If a way to do this doesn't exist. Does anyone out there have an idea what it would take to implement this functionality in hibernate.

Hibernate version: 2.1.6

Mapping documents:
Code:
   
<class name="ServiceBenefitHierarchy" table="SERVICE_BENEFIT_HIERARCHY">
      <composite-id class="ServiceBenefitHierarchyPK" name="id">
         <key-many-to-one
            class="SbhId"
            column="HIERARCHY_ID"
            name="hierarchy"
          />
         <key-many-to-one
            class="ServiceBenefitCategory"
            column="SERVICE_BENEFIT_CATEGORY_ID"
            name="serviceBenefitCategory"
          />
      </composite-id>
      <property
         column="DETAIL_SUMMARY"
         length="1"
         name="detailSummary"
         not-null="true"
         type="string"
       />
      <property
         column="HIGH_SUMMARY"
         length="1"
         name="highSummary"
         not-null="true"
         type="string"
       />
      <property
         column="RELATIONSHIP"
         length="3"
         name="relationship"
         not-null="true"
         type="string"
       />
      <set
         inverse="true"
         lazy="true"
         name="serviceBenefitCategorySet"
      >
         <key column="SERVICE_BENEFIT_CATEGORY_ID" />
         <one-to-many class="ServiceBenefitHierarchy" />
      </set>

   </class>

   <class name="SbhId" table="SBH_ID">
      <id
         column="HIERARCHY_ID"
         name="id"
         type="integer"
      >
         <generator class="sequence">
              <param name="sequence">HIERARCHY_ID_SEQ</param>
            </generator>
      </id>
      <property
         column="SERVICE_BENEFIT_HIER_EFF_DATE"
         length="7"
         name="serviceBenefitHierEffDate"
         not-null="true"
         type="date"
       />
      <many-to-one
         class="ProductType"
         name="productType"
         not-null="true"
      >
         <column name="PRODUCT_TYPE_ID" />
      </many-to-one>
      <set
         inverse="true"
         lazy="true"
         name="serviceBenefitHierarchySet"
      >
         <key column="HIERARCHY_ID" />
         <one-to-many class="ServiceBenefitHierarchy" />
      </set>
   </class>

   <class name="ServiceBenefitCategory" table="SERVICE_BENEFIT_CATEGORY">
      <id
         column="SERVICE_BENEFIT_CATEGORY_ID"
         name="id"
         type="integer"
      >
         <generator class="sequence">
              <param name="sequence">SERVICE_BENEFIT_CATEGORY_ID_SEQ</param>
            </generator>
      </id>
      <property
         column="SERVICE_BENEFIT_CATEGORY_NAME"
         length="100"
         name="serviceBenefitCategoryName"
         not-null="false"
         type="string"
       />
      <property
         column="TYPE_IND"
         length="1"
         name="typeInd"
         not-null="false"
         type="string"
       />
      <set
         inverse="true"
         lazy="true"
         name="serviceBenefitHierarchySet"
      >
         <key column="SERVICE_BENEFIT_CATEGORY_ID" />
         <one-to-many class="ServiceBenefitHierarchy" />
      </set>
   </class>


Name and version of the database you are using: Oracle 8.1.7


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 4:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You could most likely do this in Hibernate3, where you can map nearly every kind of crazy database schema by defining your own custom SQL for CRUD operations and associations. Can't think of an easy way for H2 though.


Top
 Profile  
 
 Post subject: Continued....
PostPosted: Mon Sep 27, 2004 5:17 pm 
Regular
Regular

Joined: Thu Sep 09, 2004 6:46 pm
Posts: 96
Which my current environment:

Servlet 2.2/jdk 1.3/oracle 8.1.6

is it possible to start using a version hibernate 3 that would implement this functionality?
If so which version? If not why not?

Is my only recourse otherwise to access my service layer through a getter on my domain object. My particular issue is I have a domain object whose children are also the same typed domain object but there is a complicated HQL join to retreive the results so I just can't create a mapping like the one I mentioned. I have a need to iterate through a list of these domain objects with the domain object having access to it's children so I can iterate through them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 5:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
There is Hibernate3-alpha available which can be used in your environment - its an alpha though.


Top
 Profile  
 
 Post subject: Couldn't find much doc in Hibernate3
PostPosted: Tue Sep 28, 2004 12:43 pm 
Regular
Regular

Joined: Thu Sep 09, 2004 6:46 pm
Posts: 96
Could someone give me an example how I would implement my scenario in hibernate 3 mapping file.

Thanks in advance.
Garry


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 28, 2004 12:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
http://blog.hibernate.org/cgi-bin/blosxom.cgi/Gavin%20King/customsql.html


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.