-->
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.  [ 11 posts ] 
Author Message
 Post subject: Understanding an IllegalArgumentException
PostPosted: Fri Mar 31, 2006 8:43 pm 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
Hibernate version: 3

Mapping documents:

Code:
   <class name="ProductSizeViewBean" table="Product_Size_View" mutable="false">
      <cache usage="read-only" region="productInformationCache"/>
      <composite-id>
         <key-property name="productId" type="string" column="Product_Id"/>
         <key-property name="productSizeId" type="string" column="PRODUCT_SIZE_ID"/>
         <key-property name="scentId" type="string" column="SCENT_ID"/>
         <key-property name="languageCountryId" type="string" column="LANGUAGE_COUNTRY_ID"/>
      </composite-id>
      <property name="shortProductName" type="string" column="SHORT_PRODUCT_NAME"/>
      <property name="longProductName" type="string" column="LONG_PRODUCT_NAME"/>
      <property name="sizeValue" type="float" column="SIZE_VALUE"/>
      <property name="unitId" type="string" column="UNIT_ID"/>
      <property name="unitDescription" type="string" column="UNIT_DESCRIPTION"/>
      <property name="clubSize" type="string" column="CLUB_SIZE"/>
      <property name="languageName" type="string" column="LANGUAGE_NAME"/>
      <property name="countryCode" type="string" column="COUNTRY_CODE"/>
   </class>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
Code:
[31/Mar/2006:18:30:53] info ( 3280): CORE3282: stdout: 18:30:53,235 ERROR BasicP
ropertyAccessor:167 - IllegalArgumentException in class: com.downy.productinform
ation.beans.ProductSizeViewBean, getter method of property: productId
[31/Mar/2006:18:30:53] failure ( 3280): for host 10.25.128.73 trying to POST /en
_US/productAdvisor/mostAppealingScent.do, service-j2ee reports: ApplicationDispa
tcher[] WEB2649: Servlet.service() for servlet action threw exception
javax.servlet.ServletException: IllegalArgumentException occurred calling getter
of com.downy.productinformation.beans.ProductSizeViewBean.productId; nested exc
eption is org.hibernate.PropertyAccessException: IllegalArgumentException occurr
ed calling getter of com.downy.productinformation.beans.ProductSizeViewBean.prod
uctId
        at org.apache.struts.action.RequestProcessor.processException(RequestPro
cessor.java:523)
        at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
tProcessor.java:421)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:224)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:119
4)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:807)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:908)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp
atcher.java:770)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationD
ispatcher.java:471)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDis
patcher.java:382)
        at common.filters.LanguageSelectFilter.doFilter(LanguageSelectFilter.jav
a:196)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:213)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:193)
        at common.filters.AdminFilter.doFilter(AdminFilter.java:102)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:213)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:193)
        at common.filters.TargetUriRemovalFilter.doFilter(TargetUriRemovalFilter
.java:64)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:213)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:193)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:280)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:509)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:212)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:509)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:209)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:509)
        at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProce
ssor.java:161)
        at com.iplanet.ias.web.WebContainer.service(WebContainer.java:586)
----- Root Cause -----
org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentExce
ption occurred calling getter of com.downy.productinformation.beans.ProductSizeV
iewBean.productId; nested exception is org.hibernate.PropertyAccessException: Il
legalArgumentException occurred calling getter of com.downy.productinformation.b
eans.ProductSizeViewBean.productId
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling
getter of com.downy.productinformation.beans.ProductSizeViewBean.productId
        at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPro
pertyAccessor.java:171)
        at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValue(Abstra
ctComponentTuplizer.java:121)
        at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValues(Abstr
actComponentTuplizer.java:133)
        at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoCompo
nentTuplizer.java:88)
        at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java
:307)
        at org.hibernate.type.ComponentType.isEqual(ComponentType.java:111)
        at org.hibernate.cache.CacheKey.equals(CacheKey.java:51)
        at java.util.HashMap.eq(HashMap.java:270)
        at java.util.HashMap.put(Has


Name and version of the database you are using:
Oracle 9i

My Java class:
Code:
public class ProductSizeViewBean
  implements Serializable
{
  public static final String PRODUCT_ID = "productId";
  public static final String PRODUCT_SIZE_ID = "productSizeId";
  public static final String SCENT_ID = "scentId";
  public static final String LANGUAGE_COUNTRY_ID = "languageCountryId";
  public static final String SIZE_VALUE = "sizeValue";
  public static final String CLUB_SIZE = "clubSize";

  private String productId;
  private String shortProductName;
  private String longProductName;
  private String productSizeId;
  private String scentId;
  private Float sizeValue;
  private String unitId;
  private String unitDescription;
  private String clubSize;
  private String languageCountryId;
  private String languageName;
  private String countryCode;

  public String getProductId()
  {
    return productId;
  }

  public void setProductId(String productId)
  {
    this.productId = productId;
  }

  public String getShortProductName()
  {
    return shortProductName;
  }

  public void setShortProductName(String shortProductName)
  {
    this.shortProductName = shortProductName;
  }

  public String getLongProductName()
  {
    return longProductName;
  }

  public void setLongProductName(String longProductName)
  {
    this.longProductName = longProductName;
  }

  public String getProductSizeId()
  {
    return productSizeId;
  }

  public void setProductSizeId(String productSizeId)
  {
    this.productSizeId = productSizeId;
  }

  public String getScentId()
  {
    return scentId;
  }

  public void setScentId(String scentId)
  {
    this.scentId = scentId;
  }

  public Float getSizeValue()
  {
    return sizeValue;
  }

  public void setSizeValue(Float sizeValue)
  {
    this.sizeValue = sizeValue;
  }

  public String getUnitId()
  {
    return unitId;
  }

  public void setUnitId(String unitId)
  {
    this.unitId = unitId;
  }

  public String getUnitDescription()
  {
    return unitDescription;
  }

  public void setUnitDescription(String unitDescription)
  {
    this.unitDescription = unitDescription;
  }

  public String getClubSize()
  {
    return clubSize;
  }

  public void setClubSize(String clubSize)
  {
    this.clubSize = clubSize;
  }

  public String getLanguageCountryId()
  {
    return languageCountryId;
  }

  public void setLanguageCountryId(String languageCountryId)
  {
    this.languageCountryId = languageCountryId;
  }

  public String getLanguageName()
  {
    return languageName;
  }

  public void setLanguageName(String languageName)
  {
    this.languageName = languageName;
  }

  public String getCountryCode()
  {
    return countryCode;
  }

  public void setCountryCode(String countryCode)
  {
    this.countryCode = countryCode;
  }

  public ProductSizeViewBean()
  {
  }
}


I am using Spring integration, so this is the search code:
Code:
    DetachedCriteria search = DetachedCriteria.forClass(ProductSizeViewBean.class);
    search.add(Restrictions.eq(ProductSizeViewBean.PRODUCT_ID, productId));
    search.add(Restrictions.eq(ProductSizeViewBean.SCENT_ID, scentId));
    search.add(Restrictions.eq(ProductSizeViewBean.LANGUAGE_COUNTRY_ID, languageCountryId));
    search.add(Restrictions.eq(ProductSizeViewBean.CLUB_SIZE, "No"));

return getHibernateTemplate().findByCriteria(search, startIndex, maxResults);


The view ties many tables together and I am looking for something that is in the composite key. The Select it generates works.

WHat causing such an error on a getter?

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 02, 2006 11:56 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That happens when the Method object that hibernate creates applies to one type (presumably ProductSizeViewBean.class) but the object passed into the invoke method is of another class (presumably String).

You should be able to figure out what's gone wrong by inspecting the return value of the critieria list() method. Use your debugger to check the type of each object returned in the list, and the type of each member in each object.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 7:12 am 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
tenwit wrote:
That happens when the Method object that hibernate creates applies to one type (presumably ProductSizeViewBean.class) but the object passed into the invoke method is of another class (presumably String).

You should be able to figure out what's gone wrong by inspecting the return value of the critieria list() method. Use your debugger to check the type of each object returned in the list, and the type of each member in each object.


Debugger?? That would be nice. I've never been able to get SunOne 6.1 to do remote debugging with IntelliJ.

There is another object type in the mapping with the same composite id (it is one of the tables that is in the view in question). When I configure one of them to go into a different named region, I do not get the error. This places even less confidence on H3 to return the proper objects.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 5:39 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It's not hibernate that is causing the problem, it's just allowing you to do it to yourself. The problem with this kind of exception is that it's pretty hard to track down. It's usually down to a type mismatch between the mapping file and the java code (e.g. you might have a many-to-one mapping to an object of cliass X, but your java objects hold X's id.. hence type mismatch). This shouldn't cause you to lose confidence in Hibernate, it should encourage you to do a code review, looking for mapping file vs. java code discrepencies.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 6:14 pm 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
tenwit wrote:
It's not hibernate that is causing the problem, it's just allowing you to do it to yourself. The problem with this kind of exception is that it's pretty hard to track down. It's usually down to a type mismatch between the mapping file and the java code (e.g. you might have a many-to-one mapping to an object of cliass X, but your java objects hold X's id.. hence type mismatch). This shouldn't cause you to lose confidence in Hibernate, it should encourage you to do a code review, looking for mapping file vs. java code discrepencies.


I think you are partially correct. There is a mapping issue, but it is not in the XML file, but it is in the cache region. Two different objects have the say composite key and an instance of one is being cast to another (either by H3 or ehCache). When the two object types are not in the same cache region, I do not get the error. This would lead me to believe there is no discernment of type in the cache or by H3. This is quite alarming. Perhaps it is more ehCache than H3, I do not know.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 7:06 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I'm not convinced, but you may be onto something. If you map the composite-ids as different classes, that might give hibernate/ehcache enough info to work with. It would mean dropping the component idea, but if that's not offputting, then try adding a class="" attribute on your composite-id mappings. If you use two different (though identical) classes for your two composite ids, maybe that'll give better type-checking tools to hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 8:31 pm 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
tenwit wrote:
I'm not convinced, but you may be onto something. If you map the composite-ids as different classes, that might give hibernate/ehcache enough info to work with. It would mean dropping the component idea, but if that's not offputting, then try adding a class="" attribute on your composite-id mappings. If you use two different (though identical) classes for your two composite ids, maybe that'll give better type-checking tools to hibernate.


Hmm. Interesting idea. Let me make sure I understand. Create two different classes with the 4 properties needed for the composite id and use one each on the class property for the id in the XML.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 9:29 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That's the idea. I don't know if it'll help at all, but it might, if the problem really is hibernate's inability to figure out the type of an object from the type of its key.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 11:54 pm 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
tenwit wrote:
That's the idea. I don't know if it'll help at all, but it might, if the problem really is hibernate's inability to figure out the type of an object from the type of its key.


Would this work as a public inner class to the two objects?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 12:11 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Absolutely. That's an ideal place to put a composite id class.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 10:33 am 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
tenwit wrote:
Absolutely. That's an ideal place to put a composite id class.


Very well. I shall make the change and see if that helps.

Here is the complete mapping XML for the objects in question. The objects ProductAssignmentBean and ProductSizeViewBean are not related, except via java.lang.Object. I am using cut-and-paste "reusability" to avoid an down cast collision.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.downy.productinformation.beans">
   <class name="ProductAssignmentBean" table="PRODUCT_ASSIGNMENT">
      <cache usage="read-only" region="productInformationCache"/>
      <composite-id>
         <key-property name="productId" type="string" column="Product_Id"/>
         <key-property name="productSizeId" type="string" column="PRODUCT_SIZE_ID"/>
         <key-property name="scentId" type="string" column="SCENT_ID"/>
         <key-property name="languageCountryId" type="string" column="LANGUAGE_COUNTRY_ID"/>
      </composite-id>
   </class>
   <class name="ProductInformationBean" table="PRODUCT_INFORMATION">
      <cache usage="read-only" region="productInformationCache"/>
      <id name="productId" type="string" column="PRODUCT_ID">
         <generator class="assigned" />
      </id>
      <property name="shortProductName" type="string" column="SHORT_PRODUCT_NAME"/>
      <property name="shortProductCode" type="string" column="SHORT_PRODUCT_CODE"/>
      <property name="longProductName" type="string" column="LONG_PRODUCT_NAME" />
      <property name="longProductCode" type="string" column="LONG_PRODUCT_CODE" />
      <property name="activeFlag" type="string" column="ACTIVE_FLAG" />
      <property name="newFlag" type="string" column="NEW_FLAG" />
   </class>
   <class name="ProductSizeUnitBean" table="Product_Size_Unit_View" mutable="false">
      <cache usage="read-only" region="productInformationCache"/>
      <id name="productSizeId" type="string" column="Product_Size_Id">
         <generator class="assigned"/>
      </id>
      <property name="sizeValue" type="float" column="Size_Value"/>
      <property name="unitId" type="string" column="unit_id"/>
      <property name="unitDescription" type="string" column="unit_description"/>
      <property name="clubsize" type="string" column="Club_size"/>
   </class>
   <class name="ScentInformationBean" table="Scent_Information">
      <cache usage="read-only" region="productInformationCache"/>
      <id name="scentId" type="string" column="Scent_Id">
         <generator class="assigned"/>
      </id>
      <property name="scentName" type="string" column="Name"/>
      <property name="shortScentCode" type="string" column="Short_Scent_Code"/>
      <property name="longScentCode" type="string" column="Long_Scent_Code"/>
      <property name="activeFlag" type="string" column="Active_Flag"/>
      <property name="newFlag" type="string" column="New_Flag"/>
      <property name="colorValue" type="string" column="COLOR_VALUE"/>
   </class>
   <class name="ProductSizeViewBean" table="Product_Size_View" mutable="false">
      <composite-id>
         <key-property name="productId" type="string" column="Product_Id"/>
         <key-property name="productSizeId" type="string" column="PRODUCT_SIZE_ID"/>
         <key-property name="scentId" type="string" column="SCENT_ID"/>
         <key-property name="languageCountryId" type="string" column="LANGUAGE_COUNTRY_ID"/>
      </composite-id>
      <property name="shortProductName" type="string" column="SHORT_PRODUCT_NAME"/>
      <property name="longProductName" type="string" column="LONG_PRODUCT_NAME"/>
      <property name="sizeValue" type="float" column="SIZE_VALUE"/>
      <property name="unitId" type="string" column="UNIT_ID"/>
      <property name="unitDescription" type="string" column="UNIT_DESCRIPTION"/>
      <property name="clubSize" type="string" column="CLUB_SIZE"/>
      <property name="languageName" type="string" column="LANGUAGE_NAME"/>
      <property name="countryCode" type="string" column="COUNTRY_CODE"/>
   </class>
</hibernate-mapping>


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