-->
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.  [ 1 post ] 
Author Message
 Post subject: IllegalArgumentException in class: domain.Style, getter: id
PostPosted: Mon Mar 05, 2007 3:43 am 
Newbie

Joined: Mon Mar 05, 2007 1:39 am
Posts: 10
Location: Brisbane, Australia
Why would you get an error on the getter method of a primary key? That was what I was thinking too.

Here is a bit more detail:

Code:
2007-03-05 16:44:14,734 ERROR [btpool0-4] property.BasicPropertyAccessor - IllegalArgumentException in class: com.cabs.domain.Style, getter method of property: id


And just so you know I'm not too thick, the Style.java:

Code:
public class Style {

   private int id;
   private List<Range> ranges;
   
   /*
    * Constructors
    */
   public Style() {
      super();
      setRanges(new ArrayList<Range>());
   }
   
   /*
    * Properties of this class
    */
   public void setId(int id) {
      this.id = id;
   }
   public int getId() {
      return id;
   }
   public void setRanges(List<Range> ranges) {
      this.ranges = ranges;
   }
   public List<Range> getRanges() {
      return ranges;
   }
}


Okay, there's not much can go wrong there. What about the hbm.xml for this class:

Code:
   <class name="Style" table="cab_style">
      <id name="id" column="_id" type="integer">
         <generator class="identity" />
      </id>
      <list name="ranges" cascade="all-delete-orphan">
         <key column="_stylerange" not-null="false" />
         <list-index column="stylerange_no" />
         <one-to-many class="Range" />
      </list>
   </class>


Still not much to go wrong. So when is the error happening? It's happening in my RangeServiceImpl.java, right about here:



Code:
   public Range findById(int id) {
      System.err.println("--------- RangeServiceImpl: range.findById = " + id);
      List<Range> rs = getHibernateTemplate().find(
            "select range " +
            " from " + Range.class.getCanonicalName() + " range " +
            " where range.id = ?", id);   
      System.err.println("--------- RangeServiceImpl: range.findById found objects = " + rs.size());
       return rs.isEmpty() ? null : rs.get(0);
   }


As you can imagine this might print something on the log:

--------- RangeServiceImpl: range.findById = 8
(followed by the error message)

By the way, id=8 is a valid Range record. Okay, so the record exists but what is the connection with the Style class? This is where it gets tricky, this is one of those two parents for one child type relationships.

Style: is parent 1
Rawcomp: is parent 2
Range: is a child

To create the initial range record I created a Rawcomp record, then added a Range record and saved this. Now when I try to load the Range record I get the error regarding 'IllegalArgumentException' on Style.

A Range record will have only one parent, it will be either a Rawcomp or a Style, not both. This seems to be causing me a problem.

Okay, so what have I got in my hbm.xml (I've trimmed some of the fields):


Code:
   <class name="Rawcomp" table="cab_rawcomp">
      <id name="id" column="_id" type="integer">
         <generator class="identity" />
      </id>
      <list name="ranges" cascade="all-delete-orphan">
         <key column="_rawcomprange" not-null="false" />
         <list-index column="rawcomprange_no" />
         <one-to-many class="Range" />
      </list>
   </class>

   <class name="Style" table="cab_style">
      <id name="id" column="_id" type="integer">
         <generator class="identity" />
      </id>
      <list name="ranges" cascade="all-delete-orphan">
         <key column="_stylerange" not-null="false" />
         <list-index column="stylerange_no" />
         <one-to-many class="Range" />
      </list>
   </class>

   <class name="Range" table="cab_range">
      <id name="id" column="_id" type="integer">
         <generator class="identity" />
      </id>
      <many-to-one name="rawcomp" class="Rawcomp" column="_rawcomp" />
      <many-to-one name="style" class="Style" column="_style" />
   </class>


Can somebody tell me how I should be coding this?

Cheers
Murray

_________________
Murray Collingwood
Focus Computing
http://www.focus-computing.com.au


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.