-->
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.  [ 15 posts ] 
Author Message
 Post subject: Collections of lookup values
PostPosted: Sun Aug 31, 2003 4:07 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
I have read the documentation on Collections and Parent Child Relationships numerous times and I am still unclear on a couple things (possibly because I don't want to do things the way I suspect I am supposed to...).

I have a table of valid values as follows (used for "enforcing" business rules and/when generating SELECT tags in the view of a Struts app):

Code:
valid_values { id:int, type:smallint, allowable_type:smallint }

(all three columns make up the primary key)

I have a class with three different properties on it that need to have lists of valid values for each one (e.g. follows)

Code:
class ConvolutedClass {
    //...
   private short type1;
   private List validType1Values;
   private short type2;
   private List validType2Values;
   private short type3;
   private List validType3Values;
   //...
}


I would like to be able to map this simply in some way (such as the following which I know doesn't work due to the key...):

Code:
<property name="type1" column="type1" type="short"/>
<list name="validType1Values" table="valid_values" lazy="false" cascade="none">
    <key>
        <column name="id"/>
        <column name="type"/>
    </key>
    <index column="allowable_type" type="short"/>
    <element column="allowable_type" type="short"/>
</list>

<property name="type2" column="type2" type="short"/>
<list name="validType2Values" table="valid_values" lazy="false" cascade="none">
    <key>
        <column name="id"/>
        <column name="type"/>
    </key>
    <index column="allowable_type" type="short"/>
    <element column="allowable_type" type="short"/>
</list>

<property name="type3" column="type3" type="short"/>
<list name="validType3Values" table="valid_values" lazy="false" cascade="none">
    <key>
        <column name="id"/>
        <column name="type"/>
    </key>
    <index column="allowable_type" type="short"/>
    <element column="allowable_type" type="short"/>
</list>


...but I suspect that I need to define a class and subclasses with a discriminator on the "type" column or something else more complex than what I was trying?

So any help or guidance on this subject would be appreciated.

Secondly, to possibly compound the problem, I need to be able to lookup internationalized descriptions as well and these are typically stored in other tables depending on what they relate to. How can I map one field that is a description on a given class to a table that has multiple records, one for each language, so that I only retrieve the desription in the language of the locale the user is running in?

Example:

Code:
class MyI18NClass {
    // ...
    private String description;
    // ...
}


to a table like:

Code:
my_class_i18n { id:int, language:char(2), description:varchar(50) }

where they key of the table is made up of the id and the language?

Thank-you,
David

P.S. Where can I find the discussion on why Hibernate does not/should not have a graphical mapping tool? I come from using TopLink and am finding the transition to Hibernate easy except for the mappings which I am finding excrutiating (yes I am doing this the "wrong" way where I am generating both the classes and the mappings manually).

P.P.S. I am using the Criteria only and not HQL as I wish to avoid any kind of "query" language.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2003 7:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I don't fully understand what you are trying to do, but after staring at it for a couple of minutes I think I have an inkling. Heres a couple of ideas that might help:



(1) I *think* you should be using a collection where attribute instead of one of the <key> elements in each collection mapping

(2) I suspect you should use a <bag> mapping instead of <list> ... don't think Hibernate will tolerate the <element> and <index> columns being the same - and certainly it seems semantically incorrect



Hope that is enough to help get started. Ask again if it doesn't help - I have a feeling you might be trying to do something I havn't seen before.

Quote:
I come from using TopLink and am finding the transition to Hibernate easy except for the mappings which I am finding excrutiating


Stick with it dude! It will be a pain at first but once you get it all figured, you well see the advantages :) I've had a play with toplink's GUI (which is probably one of the _better_ ones) and believe me, it is MUCH faster to write and edit Hibernate mappings once you get going.

(Also, think how impossible it would be to communicate GUI-defined mappings via this user forum. From a purely practical POV, this is a Better Way.)

Quote:
I am using the Criteria only and not HQL as I wish to avoid any kind of "query" language.



I hope you are using 2.1 beta 2 in that case! :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 8:06 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Thank-you very much for your reponse and assistance.

Quote:
(1) I *think* you should be using a collection where attribute instead of one of the <key> elements


Yes, that takes care of the problem (so far as I know at the moment) but I don't relish the "hardcoded" type=1 (et. al.) in the where although since my values aren't going to change I can live with it. I'm curious though if there is a way to specify the value of a property in the mapping?

Quote:
(2) I suspect you should use a <bag> mapping instead of <list> ... don't think Hibernate will tolerate the <element> and <index> columns being the same - and certainly it seems semantically incorrect


I switched to Set; you are correct, they cannot be the same.

Quote:
I hope you are using 2.1 beta 2 in that case! :)

I am using 2.0.3 but I may switch in a couple minutes to see what will happen to the problem described below...

Now that my mapping seems to be correct (at least correct enough for the moment not to complain) I am getting the most peculiar results (I will post full mapping and code below...).
I have three classes, the first one has a one-to-many relationship with the second which has a one-to-many relationship with the third which is the one with the simplified snipit I had problems with mapping.
The strange thing is that the List of instances of the "middle" class held by the first class contains 19 null entries and 1 seemingly valid one at the end of the List. There is no data corellation that I can see for the 19 null records. Following is the code and the debugging output:

The mappings:
Code:
<hibernate-mapping>

   <!-- WorksheetProduct -->
   <class name="com.fgl.ina.costestimation.WorksheetProduct" table="worksheet_product">
      <id name="ID" type="integer" column="worksheet_product_id">
         <generator class="net.sf.hibernate.id.IncrementGenerator"/>
      </id>
<!--      <many-to-one name="worksheetID"           column="worksheet_id" not-null="true"/>-->
      <property    name="productID"             column="ina_prod_id"  type="long"/>
      <property    name="unitOfMeasureQuantity" column="uom_qty"      type="float"/>

      <list name="costFactors" table="worksheet_factor" lazy="false" cascade="all">
         <key column="worksheet_product_id"/>
         <index column="worksheet_factor_id"/>
         <one-to-many class="com.fgl.ina.costestimation.WorksheetFactor"/>
      </list>
   </class>

   <!-- WorksheetHeader -->
   <class name="com.fgl.ina.costestimation.WorksheetHeader" table="worksheet_header">
      <id name="worksheetID" type="integer" column="worksheet_id">
         <generator class="net.sf.hibernate.id.IncrementGenerator"/>
      </id>
      <property name="description"       column="description"         type="string"/>
      <property name="vendor"            column="vendor_no"           type="string"    not-null="true"/>
      <property name="status"            column="status"              type="short"     not-null="true"/>
      <property name="createdBy"         column="created_by"          type="string"    not-null="true"/>
      <property name="createdDate"       column="created_date"        type="timestamp" not-null="true"/>
      <property name="revisedDate"       column="last_revision_date"  type="timestamp" not-null="true"/>
      <property name="foreignStatus"     column="foreign_status"      type="short"     not-null="true"/>
      <property name="foreignContractNo" column="foreign_contract_no" type="long"      not-null="true"/>
      <property name="comments"          column="comments"            type="string"/>

      <list name="products" table="worksheet_product" lazy="false" cascade="all">
         <key column="worksheet_id"/>
         <index column="worksheet_product_id"/>
         <one-to-many class="com.fgl.ina.costestimation.WorksheetProduct"/>
      </list>
   </class>

   <!-- WorksheetFactor -->
   <class name="com.fgl.ina.costestimation.WorksheetFactor" table="worksheet_factor">
      <id name="ID" type="integer" column="worksheet_factor_id">
         <generator class="net.sf.hibernate.id.IncrementGenerator"/>
      </id>
<!--      <many-to-one name="worksheetProductID" column="worksheet_product_id" />-->
      <property    name="costFactorID"       column="cost_factor_id"       type="integer"/>

      <property    name="calculatedType"     column="calculated_type"       type="short"/>
      <set order-by="allowable_type" name="calculatedTypeOptions" table="cost_factor_values" lazy="false" cascade="none" where="type=1">
         <key column="cost_factor_id"/>
<!--         <index column="allowable_type" type="short"/>-->
         <element column="allowable_type" type="short"/>
      </set>

      <property name="costFactorValue" column="cost_factor_value" type="float"/>
      <property name="foreignAmount"   column="foreign_amount"    type="float"/>

      <property name="currencyType"    column="currency_type"     type="short"/>
      <set order-by="allowable_type" name="currencyTypeOptions" table="cost_factor_values" lazy="false" cascade="none" where="type=2">
         <key column="cost_factor_id"/>
<!--         <index column="allowable_type" type="short"/>-->
         <element column="allowable_type" type="short"/>
      </set>

      <property name="exchangeRate"    column="exchange_rate"     type="float"/>

      <property name="proratingType"   column="prorating_type"    type="short"/>
      <set order-by="allowable_type" name="proratingTypeOptions" table="cost_factor_values" lazy="false" cascade="none" where="type=3">
         <key column="cost_factor_id"/>
<!--         <index column="allowable_type" type="short"/>-->
         <element column="allowable_type" type="short"/>
      </set>

<!--      <property name="language" column="locale" type="string"/>-->
<!--      <property name="description" column="description" type="string"/>-->
   </class>
</hibernate-mapping>


The method for retrieving instances:
Code:
   /**
    * Retrieves a persisted worksheet (i.e. {@link WorksheetHeader} instance) identified by the specified ID.
    * @param worksheetID the ID of the worksheet to retrieve
    * @return the <code>WorksheetHeader</code> instance.
    * @throws Exception
    */
   public static WorksheetHeader getWorksheetByID(int worksheetID) throws Exception {
      Session session = DataAccessServiceHelper.getSession();
      WorksheetHeader returnHeader = null;
      try {
         returnHeader = (WorksheetHeader)session.createCriteria(WorksheetHeader.class).add(
               Expression.eq(WORKSHEET_ID, new Integer(worksheetID))).list().get(0);
      } catch (Throwable t) {
         LogFactory.getLog(WorksheetService.class).error("Could not load worksheet " + worksheetID, t);
      } finally {
         session.close();
      }
      return returnHeader;
   }


The class WorksheetHeader:
Code:
package com.fgl.ina.costestimation;

import java.util.Date;
import java.util.List;
import java.util.ArrayList;

/**
* Bean containing the header level information for a worksheet as well as the <code>Collection</code>s of sub data.
* @author David Duffy
*/
public class WorksheetHeader {
   private int worksheetID = 0;
   private String description = null;
   private String vendor = null;
   private short status = 0;
   private String createdBy = null;
   private Date createdDate = null;
   private Date revisedDate = null;
   private short foreignStatus = 0;
   private Long foreignContractNo = null;
   private String comments = null;

   private String vpn = null;

   private List products = new ArrayList();

   /**
    * A lot of getters and setters follow...
    */

   // ...
}


The debugging line:
Code:
System.out.println("\n\n*** worksheet.products = " + worksheet.getProducts() + "\n");


Prior to the above line running the variable worksheet has been set to the return value of the getWorksheetByID(...) method.
The println(...) generates the following:

Code:
*** worksheet.products = [null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, com.fgl.ina.costesti
mation.WorksheetProduct@129b073]


Any ideas why this is occurring?

Thank-you again.
Sincerely,
David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 8:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
hmmmm not quite sure why this would happen ..... what is the generated SQL looking like?


Try looking at the Hibernate log (in debug level) and see how many rows in the resultset.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 1:49 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
I cannot download version 2.1 beta 2, each attempt from different mirrors for both the .zip and the .tar ball versions results in a message that the archive is incomplete or corrupt.

I cannot login anonymously to the CVS server either to checkout the code and compile it myself so I am still running version 2.0.3.

The problem with the null records was the result of my failure to consider that I had mapped a column as the index which does not start at 0 which of course resulted in as many null entries in the List as per the value specified as the index since the "real" record would be stored at that index position in the List thus forcing the List to pad with nulls up to that point.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 3:29 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Quote:
The problem with the null records was the result of my failure to consider that I had mapped a column as the index which does not start at 0


Which leads me to a dilema, I need an indexed collection for a jsp <logic:iterate> tag and it seems the only thing I can use is a map with the index type set as string even though the column is really an integer.
Is this really the only way?

Well, at least it works, my only remaining concern (at least until I have to update) is how to map internationalized descriptions so that I can populate a description field in the user's language but I'll post that seperately.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 6:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I need an indexed collection for a jsp <logic:iterate> tag



just use a <bag>. If you require an ordering, use the order-by attribute


Quote:
I cannot download version 2.1 beta 2, each attempt from different mirrors for both the .zip and the .tar ball versions results in a message that the archive is incomplete or corrupt.



ooh let me have a look at that....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 7:17 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Quote:
I cannot download version 2.1 beta 2, each attempt from different mirrors for both the .zip and the .tar ball versions results in a message that the archive is incomplete or corrupt.


ooh let me have a look at that....


I managed to get a .tar ball from the mirror in Ireland (I think) that seemed to extract okay, at least the hibernate2.jar which is what I was after. I think I tried Pheonix, Minneapolis, Prague, some I don't remember, and finally Dublin (in that order) and each yielded a corrupt archive on my end except the last .tar from Dublin. I may not have tried both the .zip and .tar.gz on all the mirrors I tried. Not sure if it's something on my end or not but I haven't had problems with any other files and I tried both WinRAR and WinZip for extracting the archives that were not working.


Top
 Profile  
 
 Post subject: lazy="false" inverted or ignored in 2.1 beta 2?
PostPosted: Tue Sep 02, 2003 9:19 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Now that I've switched to using version 2.1 beta 2 all of my collections mapped with lazy="false" are generating LazyInitializationExceptions?

Even though lazy defaults to false, shouldn't explicitly setting it to false still work?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 5:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Should do! Are you *sure* about this? I don't really believe it, after glancing at the code....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 12:33 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Quote:
Are you *sure* about this?


I am absolutely positive that "something" is throwing a LazyInitializationException when running 2.1 beta 2 that does not occur when running 2.0.3. I switched back to 2.0.3 and the problem went away, I switched to 2.1 b2 again and the problem promptly returned, I did not change anything except the version of Hibernate2.jar that I was using.

My mapping file is as follows:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

   <!-- WorksheetProduct -->
   <class name="com.fgl.ina.costestimation.WorksheetProduct" table="worksheet_product">
      <id name="ID" type="integer" column="worksheet_product_id">
         <generator class="net.sf.hibernate.id.IncrementGenerator"/>
      </id>
<!--      <many-to-one name="worksheetID"           column="worksheet_id" not-null="true"/>-->
      <property    name="productID"             column="ina_prod_id"  type="long"/>
      <property    name="unitOfMeasureQuantity" column="uom_qty"      type="float"/>

      <map name="costFactors" table="worksheet_factor" lazy="false" cascade="all" order-by="worksheet_factor_id">
         <key column="worksheet_product_id"/>
         <index column="worksheet_factor_id" type="string"/>
         <one-to-many class="com.fgl.ina.costestimation.WorksheetFactor"/>
      </map>
   </class>

   <!-- WorksheetHeader -->
   <class name="com.fgl.ina.costestimation.WorksheetHeader" table="worksheet_header">
      <id name="worksheetID" type="integer" column="worksheet_id">
         <generator class="net.sf.hibernate.id.IncrementGenerator"/>
      </id>
      <property name="description"       column="description"         type="string"/>
      <property name="vendor"            column="vendor_no"           type="string"    not-null="true"/>
      <property name="status"            column="status"              type="short"     not-null="true"/>
      <property name="createdBy"         column="created_by"          type="string"    not-null="true"/>
      <property name="createdDate"       column="created_date"        type="timestamp" not-null="true"/>
      <property name="revisedDate"       column="last_revision_date"  type="timestamp" not-null="true"/>
      <property name="foreignStatus"     column="foreign_status"      type="short"     not-null="true"/>
      <property name="foreignContractNo" column="foreign_contract_no" type="long"      not-null="true"/>
      <property name="comments"          column="comments"            type="string"/>

      <map name="products" table="worksheet_product" lazy="false" cascade="all" order-by="worksheet_product_id">
         <key column="worksheet_id"/>
         <index column="worksheet_product_id" type="string"/>
         <one-to-many class="com.fgl.ina.costestimation.WorksheetProduct"/>
      </map>
   </class>

   <!-- WorksheetFactor -->
   <class name="com.fgl.ina.costestimation.WorksheetFactor" table="worksheet_factor">
      <id name="ID" type="integer" column="worksheet_factor_id">
         <generator class="net.sf.hibernate.id.IncrementGenerator"/>
      </id>
<!--      <many-to-one name="worksheetProductID" column="worksheet_product_id" />-->
      <property    name="costFactorID"       column="cost_factor_id"       type="integer"/>

      <property    name="calculatedType"     column="calculated_type"       type="short"/>
      <set name="calculatedTypeOptions" lazy="false" cascade="none">
         <key column="cost_factor_id"/>
         <one-to-many class="com.fgl.ina.costestimation.lookups.CalculatedTypeLookup"/>
      </set>

      <property name="costFactorValue" column="cost_factor_value" type="float"/>
      <property name="foreignAmount"   column="foreign_amount"    type="float"/>

      <property name="currencyType"    column="currency_type"     type="short"/>
      <set name="currencyTypeOptions" lazy="false" cascade="none">
         <key column="cost_factor_id"/>
         <one-to-many class="com.fgl.ina.costestimation.lookups.CurrencyTypeLookup"/>
      </set>

      <property name="exchangeRate"    column="exchange_rate"     type="float"/>

      <property name="proratingType"   column="prorating_type"    type="short"/>
      <set name="proratingTypeOptions" lazy="false" cascade="none">
         <key column="cost_factor_id"/>
         <one-to-many class="com.fgl.ina.costestimation.lookups.ProratingTypeLookup"/>
      </set>

<!--      <property name="language" column="locale" type="string"/>-->
<!--      <property name="description" column="description" type="string"/>-->
   </class>
</hibernate-mapping>


The Exception stack trace is as follows (sorry it's a mess, there seem to be at least two trace dumps occurring simultaneously):
Code:
ERROR [web-3] (LazyInitializationException.java:25) - Failed to lazily initializ
e a collection - no Session
net.sf.hibernate.La03/09 10:18:29 error Failed to lazily initialize a collection
- no Session
net.sf.hibernate.LazyInitializationException: FailedzyInitializationException: F
ailed to lazily initialize a collection - no Session
        at net.sf.hibernate.collection.PersistentColl to lazily initialize a col
lection - no Session
        at net.sf.hibernate.collection.PersistentCollection.initialize(Persisten
tColleection.initialize(PersistentCollection.java:164)
        at net.sf.hibernate.collection.PersistentCollection.read(PersistentColle
ctionction.java:164)
        at net.sf.hibernate.collection.PersistentCollection.read(PersistentColle
ction.java:63)
        at net.sf.hibernate.c.java:63)
        at net.sf.hibernate.collection.Map.entrySet(Map.java:174)
        at org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:
306)
        at org.apache.struts.taglib.nested.logic.NestedIterateTag.doStartTag(Nes
tedIterateTag.java:116)
        at jrunollection.Map.entrySet(Map.java:174)
        at org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:
306)
        at org.apa__jsp__costEstimation__worksheetHeader2ejsp27._jspService(jrun
__jsp__costEstimation__worksheetHeader2ejsp27.java:607)
        at jrun.che.struts.taglib.nested.logic.NestedIterateTag.doStartTag(Neste
dIterateTag.java:116)
        at jrun__jsp__costEstimation__worksheetHjsp.runtime.HttpJSPServlet.servi
ce(HttpJSPServlet.java:43)
        at jrun.jsp.JSPServlet.service(JSPServlet.java:119)
        at jrun.servleader2ejsp27._jspService(jrun__jsp__costEstimation__workshe
etHeader2ejsp27.java:607)
        at jrun.jsp.runtime.HttpJSPServlet.servicet.ServletInvoker.invoke(Servle
tInvoker.java:91)
        at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
        at jre(HttpJSPServlet.java:43)
        at jrun.jsp.JSPServlet.service(JSPServlet.java:119)
        at jrun.servlet.ServletInvoker.invoke(ServletIun.servlet.JRunRequestDisp
atcher.invokeNext(JRunRequestDispatcher.java:439)
        at jrun.servlet.JRunRequestDispatcher.forwardInvoknvoker.java:91)
        at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
        at jrun.servlet.JRunRequestDispatcher.e(JRunRequestDispatcher.java:409)
        at jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java
:178)
        at org.apachinvokeNext(JRunRequestDispatcher.java:439)
        at jrun.servlet.JRunRequestDispatcher.forwardInvoke(JRunRequestDispatche
r.java:409)e.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069
)
        at org.apache.struts.action.RequestProcessor.processFor
        at jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java
:178)
        at org.apache.struts.action.RequestProcessor.wardConfig(RequestProcessor
.java:455)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:279)
        at orgdoForward(RequestProcessor.java:1069)
        at org.apache.struts.action.RequestProcessor.processForwardConfig(Reques
tProcessor.java:455)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:279)
        at org.apache.struts.action.ActionServl.apache.struts.action.ActionServl
et.process(ActionServlet.java:1482)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(Httet.process(ActionServlet.ja
va:1482)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
        at javax.servletpServlet.java:853)
        at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
        at jrun.servlet.JRunInvokerChain.invokeNext.http.HttpServlet.service(Htt
pServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at jrun.serv(JRunInvokerChain.java:42)
        at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:
252)
        at jrun.servlet.Servlet.ServletInvoker.invoke(ServletInvoker.java:91)
        at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
        at jletEngineService.dispatch(ServletEngineService.java:527)
        at jrun.servlet.http.WebService.invokeRunnable(WebService.java:168)
run.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:252)
        at jrun.servlet.ServletEngineService.dispatch(Servlet   at jrunx.schedul
er.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
        at jrunx.scheduler.WorkerThread.run(WorkerThEngineService.java:527)
        at jrun.servlet.http.WebService.invokeRunnable(WebService.java:168)
        at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.j
ava:451)
        at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

read.java:66)


I can say specifically that it definitely does occur on both the maps I have defined but I think not on the three sets I have on the third level one-to-many class.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 12:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
OK then. Well, would you please submit a main() method to JIRA. I simply havn't been able to reproduce this. (And I have tried.)

I believe you, but it must be in some obscure case....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 12:56 am 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Quote:
OK then. Well, would you please submit a main() method to JIRA


Ok, I will try to get that done tomorrow morning, my immediate priority is to get some sleep and then try to figure out how to get the correct results in my collections of lookups. Everything I have tried so far has failed because the primary key of the parent object is not the key for the lookups and I haven't been able to figure out how to use a different field as the key (I believe there must be a way and that I am just missing it so please stop me if I'm on a dead end).

I used to think I had a one-to-many relationship but I was not thinking about it from the correct perspective. Regardless, I seem to be doing the same wrong things no matter what my perspective or approach. I actually have a standard many-to-many relationship where the cross reference key for the parent to the lookups (which are reused by many objects) is not the primary key of the parent.

My most recent attempt has been following the last example in 5.12 of the reference documentation with version 2.1b2. Everything tries to use the primary key of the parent object instead of the field that actually has the key, I've found several ways of "successfully" mapping the tables and objects but the resultant queries don't return any values because the primary key is bound to parameter 1 instead of the value of the field that is the key for the lookups that I can't figure out how to specify. Guidance on this would be most appreciated and then I can worry about learning about JIRA and writing a test to demonstrate how I'm getting the LazyInitializationException only with the 2.1b2 jar.

Thank-you very much for your help and patience. Please forgive my numerous lengthy posts to this topic.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 12:39 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Okay I give up, somebody please help me, I can't figure out how to map a many-to-many collection that is not keyed to the primary key of the parent and I've been accomplishing almost nothing because I can't get useful mappings!

How do you map this in version 2.x?
Code:
tables:
    big_table { id:int, some_data:varchar(50), lookup_id:int, more_data:int }
    lookup_table { lookup_id:int, lookup_value_i_want:varchar(50) }

* there is no cross reference table nor is there going to be one.

classes:
    class BigClass {
        private int id;
        private String someData;
        private int lookupId;
        private Map lookupValues;    // collection of Lookups
        // ...
    }

    class Lookup {
        private int lookupId;
        private String valueIWant;
        // ...
     }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 9:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I can't figure out how to map a many-to-many collection that is not keyed to the primary key of the parent


If you mean what you think you mean, ie. you have an uglyrelational model where the foreign key in link table references a unique key that is not the primary key, then this is not possible in Hibernate.

You should be able to write a UserType that executes some direct SQL and fetches a collection of objects.


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