-->
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: Component Confusion Redux
PostPosted: Thu Oct 02, 2003 1:54 am 
Newbie

Joined: Tue Sep 16, 2003 7:05 pm
Posts: 3
Location: Los Angeles, CA
Folks,

OK, I have mapping:

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>
   <class name="com.i21.eQuote.model.ApplicantBO" table="EAPPLICANT" schema="EQTDEV">
      <id name="applicantId" column="EAPPLICANT_ID">
         <generator class="identity"/>
      </id>
      <component name="homePhone" class="com.i21.eQuote.model.PhoneNumberBO">
         <property name="phoneNumber" column="HOME_PHONE_NBR"/>
      </component>
      <list name="viewedProducts" table="VIEWED_PRODUCT" cascade="all">
         <key column="EAPPLICANT_ID"/>
         <index column="VIEWED_PRODUCT_SEQ_NBR"/>
         <element column="PRODUCT_ID" type="string"/>
      </list>
      <property name="ratePlan" column="RATE_PLAN"/>
      <property name="password" column="ACCT_PASSWORD_TXT"/>
      <component name="residentialAddress" class="com.i21.eQuote.model.AddressBO">
         <property name="street1" column="RES_ADDR_NAME"/>
         <property name="street2" column="RESIDENT_UNIT"/>
         <property name="city" column="RES_CITY_NAME"/>
         <property name="geoState" column="RES_STATE_NAME"/>
         <property name="postal" column="RES_ZIP_CODE"/>
      </component>
      <component name="referrer" class="com.i21.eQuote.model.ReferrerBO">
         <property name="firstName" column="REFERRAL_FIRST_NAME"/>
         <property name="lastName" column="REFERRAL_LAST_NAME"/>
         <property name="mi" column="REFERRAL_MIDDLE_INITIAL"/>
         <property name="phoneNumber" column="REFERRAL_PHONE_NBR"/>
         <property name="policyNumber" column="REFERRAL_POLICY_NBR"/>
      </component>
      <property name="postQuoteEmailStatusCode" column="POST_QUOTE_EMAIL_STATUS"/>
      <list name="promotions" table="PROMOTION" cascade="all">
         <key column="EAPPLICANT_ID"/>
         <index column="PROMOTION_SEQ_NBR"/>
         <one-to-many class="com.i21.eQuote.model.PromotionBO"/>
      </list>
      <property name="permitEmail" column="PERMIT_SPAM_FLG"/>
      <property name="allowCreditReport" column="PERMIT_CREDIT_RPT_FLG"/>
      <property name="referred" column="REFERRAL_FLG"/>
      <component name="mailingAddress" class="com.i21.eQuote.model.AddressBO">
         <property name="street1" column="MAIL_ADDR_NAME"/>
         <property name="street2" column="MAILING_UNIT"/>
         <property name="city" column="MAIL_CITY_NAME"/>
         <property name="geoState" column="MAIL_STATE_NAME"/>
         <property name="postal" column="MAIL_ZIP_CODE"/>
      </component>
      <property name="email" column="EMAIL_ADDRESS_TXT"/>
      <list name="quotes" table="EQUOTE" cascade="all">
         <key column="EAPPLICANT_ID"/>
         <index column="EQUOTE_SEQ_NBR"/>
         <one-to-many class="com.i21.eQuote.model.QuoteBO"/>
      </list>
      <set name="sourceCodes" table="SOURCE_CODE" cascade="all" sort="com.i21.eQuote.util.SourceCodeComparer">
         <key column="EAPPLICANT_ID"/>
         <one-to-many class="com.i21.eQuote.model.SourceCodeBO"/>
      </set>
   </class>
</hibernate-mapping>


And I have my AddressBO class:

Code:
public class AddressBO extends EQuoteBaseBO
{
   public static final long serialVersionUID = 12345L;
   
   private String city;
   private String geoState;
   private String postal;
   private String street1;
   private String street2;

   public AddressBO()
   {
   }

   public AddressBO(
      String street1,
      String street2,
      String city,
      String geoState,
      String postal)
   {
      this.street1 = street1;
      this.street2 = street2;
      this.city = city;
      this.geoState = geoState;
      this.postal = postal;
   }
   
   public String getCity()
   {
      return city;
   }

   public String getGeoState()
   {
      return geoState;
   }

   public String getPostal()
   {
      return postal;
   }

   public String getStreet1()
   {
      String value = (null == street1) ? "" : street1;
      return value;
   }

   public String getStreet2()
   {
      String value = (null == street2) ? "" : street2;
      return value;
   }
   
   /**
    * The leading digits of street1 or an empty string if none. Possibly empty,
    * but never null.
    */
   public String getStreetNumber()
   {
      String result = extractFromStreet1("/^([\\d]*)/");
      return result;
   }
   
   /**
    * The text of street1 between any leading digits and any trailing digits
    * (and a possible #). Possibly empty, but never null.
    */
   public String getStreetName()
   {
      String result = extractFromStreet1("/^[\\d]*\\s([A-Za-z\\s\\.-]*)/");
      return result;
   }
   
   public void setCity(String value)
   {
      if (getLog().isDebugEnabled())
      {
         getLog().debug("value = " + value);
      }
      city = value;
   }

   public void setGeoState(String value)
   {
      if (getLog().isDebugEnabled())
      {
         getLog().debug("value = " + value);
      }
      geoState = value;
   }

   public void setPostal(String value)
   {
      if (getLog().isDebugEnabled())
      {
         getLog().debug("value = " + value);
      }
      postal = value;
   }

   public void setStreet1(String value)
   {
      if (getLog().isDebugEnabled())
      {
         getLog().debug("value = " + value);
      }
      street1 = value;
   }

   public void setStreet2(String value)
   {
      if (getLog().isDebugEnabled())
      {
         getLog().debug("value = " + value);
      }
      street2 = value;
   }
   
   protected String extractFromStreet1(String pattern)
   {
      String result = "";
      String street1 = getStreet1();
      Perl5Util regex = new Perl5Util();
      boolean foundMatch = regex.match(pattern, street1);
      if (foundMatch)
      {
         result = regex.group(1).trim();
      }
      return result;
   }
}


This gets me "rethrown as net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling: object is not an instance of declaring class getter of com.i21.eQuote.model.AddressBO.street1"

I'm afraid I'm baffled. Any advice would be greatly appreciated.


Top
 Profile  
 
 Post subject: Emergency!
PostPosted: Fri Oct 03, 2003 7:18 pm 
Newbie

Joined: Tue Sep 16, 2003 7:05 pm
Posts: 3
Location: Los Angeles, CA
Folks,

I hate to beg, and I hate to reply to my own post, but this is now a matter of the most dire urgency: I cannot see anything wrong with my mapping, and others have apparently gotten this to work. Any help at all would be greatly appreciated.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2003 9:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
What version of hibernate are you using? How about the code causing this exception; what does it look like? What is the full stack trace for the exception you are getting? Have you tried turning off reflection optimization?

In general, is is bad to do things like:
Code:
   public String getStreet1()
   {
      String value = (null == street1) ? "" : street1;
      return value;
   }


if you need this type of functionality, it is usually much better to do something like:
Code:
   // Hibernate mapped property
   public String getStreet1()
   {
      return street1;
   }

   // Public accessible accessor
   public String getStreet1Safely()
   {
      return null == street1 ? "" : street1;
   }


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.