Using Hibernate 2.0.3 We have a table "panel_demographics" (xml at bottom) which holds foreign keys to many other tables. These other (metadata) tables all look basically the same, at the bottom "Education" is an example. A query like: PanelDemographics panelDemographics = (PanelDemographics) session.load(PanelDemographics.class, new Long(1)); will generate about 7000 characters of sql and takes about 15 seconds to execute.
I wanted to know if the following setup is possible: All the foreign tables should be cached indefinately. There are only a couple rows in each. Is a way for hibernate to, when loading PanelDemographics, the sql generated would just select the id's of the foreign tables, then grab the objects from the cache. The following... PanelDemographics panelDemographics = (PanelDemographics) session.load(PanelDemographics.class, new Long(1)) would generate sql like "select education_id, household_size_id, etc... where panel_id = 1" Then Hibernate would use the ids to grab the references from cache and set them on PanelDemographics. I tried the following: I have JCS configured to cache each metadata table, along with <jcs-cache usage="read-only"/> in each <class> tag. 1. Adding a proxy to the PanelDemographics class makes everything load in about .5 seconds. But obviously, when the session is closed and the object is passed to the UI for rendering, all of its references are not initialized. So, doing a Hibernate.initialize(panelDemographics); still takes about 15 seconds. 2. Adding a proxy to each metadata table, then calling initialize on each does what I am looking for (I think). long start = System.currentTimeMillis(); panelPersonal = (PanelPersonal) session.load(PanelPersonal.class, panel.getId()); panelDemographics = (PanelDemographics) session.load(PanelDemographics.class, panel.getId()); System.out.println("Time: " + (System.currentTimeMillis() - start)); // Time: 506 start = System.currentTimeMillis(); Hibernate.initialize(panelDemographics.getEducation()); Hibernate.initialize(panelDemographics.getChild0005()); Hibernate.initialize(panelDemographics.getChild0609()); Hibernate.initialize(panelDemographics.getChild1012()); Hibernate.initialize(panelDemographics.getChild1317()); Hibernate.initialize(panelDemographics.getEthnicity()); Hibernate.initialize(panelDemographics.getGender()); Hibernate.initialize(panelDemographics.getIndustry()); Hibernate.initialize(panelDemographics.getOccupation()); Hibernate.initialize(panelDemographics.getEmployment()); Hibernate.initialize(panelDemographics.getInternetHours()); Hibernate.initialize(panelDemographics.getInternetHowOften()); Hibernate.initialize(panelDemographics.getPresenceChildren()); Hibernate.initialize(panelDemographics.getHouseholdIncome()); Hibernate.initialize(panelDemographics.getPersonalIncome()); Hibernate.initialize(panelDemographics.getHouseholdSize()); Hibernate.initialize(panelDemographics.getInternetSpeed()); Hibernate.initialize(panelDemographics.getMaritalStatus()); System.out.println("Init Time: " + (System.currentTimeMillis() - start)); // Init Time: 206 Am I doing this the right way or is there an easier way? Also, since I have to also retrieve all the data from a metadata table to display it along with the selected option, I now have to initialize these objects everywhere I use them. public static Title[] selectAllTitle(Session session) throws HibernateException { Title[] o = null; List list = session.find("SELECT o FROM Title o"); o = new Title[list.size()]; list.toArray(o); // Initialize each for (int i = 0; i < o.length; i++) { Hibernate.initialize(o[i]); } return o; } Thanks for your help! Joseph Toth ---------------------------------------------------------------------------- ------------------------------------------------------- Below is the xml for PanelDemographics and an example metadata table (Education). ---------------------------------------------------------------------------- ------------------------------------------------------- <class name="com.lsr.eclipse.framework.model.PanelDemographics" table="panel_demographics"> <id column="panel_id" name="panelId" type="java.lang.Long"> <generator class="assigned"/> </id> <many-to-one column="household_size_id" name="householdSize" class="com.lsr.eclipse.framework.model.HouseholdSize"/> <many-to-one column="ethnicity_id" name="ethnicity" class="com.lsr.eclipse.framework.model.Ethnicity"/> <property column="birth_date" length="23" name="birthDate" type="java.util.Date"/> <many-to-one column="internet_how_often_id" name="internetHowOften" class="com.lsr.eclipse.framework.model.InternetHowOften"/> <many-to-one column="internet_hours_id" name="internetHours" class="com.lsr.eclipse.framework.model.InternetHours"/> <property column="html_preference" length="3" name="htmlPreference" type="java.lang.Integer"/> <property column="chief_wage_earner" length="10" name="chiefWageEarner" type="java.lang.Integer"/> <many-to-one column="gender_id" name="gender" class="com.lsr.eclipse.framework.model.Gender"/> <many-to-one column="marital_status_id" name="maritalStatus" class="com.lsr.eclipse.framework.model.MaritalStatus"/> <many-to-one column="education_id" name="education" class="com.lsr.eclipse.framework.model.Education"/> <many-to-one column="occupation_id" name="occupation" class="com.lsr.eclipse.framework.model.Occupation"/> <many-to-one column="employment_id" name="employment" class="com.lsr.eclipse.framework.model.Employment"/> <many-to-one column="industry_id" name="industry" class="com.lsr.eclipse.framework.model.Industry"/> <many-to-one column="child_0005" name="child0005" class="com.lsr.eclipse.framework.model.Child"/> <many-to-one column="child_0609" name="child0609" class="com.lsr.eclipse.framework.model.Child"/> <many-to-one column="child_1012" name="child1012" class="com.lsr.eclipse.framework.model.Child"/> <many-to-one column="child_1317" name="child1317" class="com.lsr.eclipse.framework.model.Child"/> <many-to-one column="household_income_id" name="householdIncome" class="com.lsr.eclipse.framework.model.HouseholdIncome"/> <many-to-one column="internet_speed_id" name="internetSpeed" class="com.lsr.eclipse.framework.model.InternetSpeed"/> <many-to-one column="personal_income_id" name="personalIncome" class="com.lsr.eclipse.framework.model.PersonalIncome"/> <property column="presence_children_id" length="3" name="presenceChildren" type="java.lang.Integer"/> <many-to-one column="chief_occupation_id" name="chiefOccupation" class="com.lsr.eclipse.framework.model.Occupation"/> <many-to-one column="chief_employment_id" name="chiefEmployment" class="com.lsr.eclipse.framework.model.Employment"/> <many-to-one column="chief_industry_id" name="chiefIndustry" class="com.lsr.eclipse.framework.model.Industry"/> <property column="ethnic_other_text" length="128" name="ethnicOtherText" type="java.lang.String"/> <property column="internet_speed_other" length="128" name="internetSpeedOther" type="java.lang.String"/> <property column="expecting" length="23" name="expecting" type="java.util.Date"/> <property column="social_class_code" length="3" name="socialClassCode" type="java.lang.String"/> <property column="last_mod_dt" length="23" name="lastModDt" formula="getdate()" not-null="true" type="java.util.Date"/> </class> <class name="com.lsr.eclipse.framework.model.Education" table="education" proxy="com.lsr.eclipse.framework.model.Education"> <jcs-cache usage="read-only"/> <id column="race_id" name="id" type="java.lang.Integer"> <generator class="assigned"/> </id> <property column="description" length="255" name="description" not-null="true" type="java.lang.String"/> <property column="isvisible" length="1" name="isvisible" not-null="true" type="java.lang.Boolean"/> <property column="isdefault" length="1" name="isdefault" not-null="true" type="java.lang.Boolean"/> <property column="sequence" length="3" name="sequence" type="java.lang.Integer"/> <property column="last_mod_dt" length="23" name="lastModDt" formula="getdate()" not-null="true" type="java.util.Date"/> <property column="last_mod_userid" length="10" name="lastModUserid" formula="user_id()" not-null="true" type="java.lang.Integer"/> </class> ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel