-->
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: Argument type mismatch when loading data, what's wrong?
PostPosted: Fri Sep 19, 2008 8:49 pm 
Newbie

Joined: Fri Sep 19, 2008 7:14 pm
Posts: 1
I'm working on a middleware that I have to develope for a course at university. The database was a perious task and the fortend is given. My problem is probalby about mismatching datatypes - sounds easy but it is driving me nuts because changing the frontendcode would probably the easiest way to solve it but thats not allowed unfortunately.

First off, the relevant code of the frontend:

Code:
public interface CountryDataInterface {
   ...
   public abstract CityDataInterface getCapital();
   public abstract List<CityDataInterface> getCities();
   ...
}

public class CountryData implements CountryDataInterface {
   ...
   private CityDataInterface capital = null;
   private List<CityDataInterface> cities = null;
   ...
   public CityDataInterface getCapital() {
      return capital;
   }
   public List<CityDataInterface> getCities() {
      return cities;
   }
   public void setCapital(CityDataInterface capital) {
      this.capital=capital;
   }
   public void setCities(List<CityDataInterface> cities) {
      this.cities = cities;
   }
   ...
}


Now, I got my mapping file for CountryData:

Code:
<class name="wfb.definitions.CountryData" table="prak228.myCountryView">
...
   <many-to-one name="capital" class="wfb.definitions.CityData" unique="true" />
   <set name="cities" table="prak228.myCityToCountryView">
      <key column="landName" not-null="true"/>
      <many-to-many class="wfb.definitions.CityData" column="name" unique="true"/>
   </set>
   <!-- countries and cities are linked in the view myCityToCountryView with landName referencing a country and name referencing a city -->
...
</class>

I'm not quite sure if it's correct, although it sould be according to a few examples I've worked through.

And finally my applications with the following functionality:

Code:
...
public CountryDataInterface getCountryData(String countryName) {
   Query query = session.createQuery("from CountryData cd where cd.name = :cname");
   query.setString("cname",countryName);
   return query.list();
}
...


I'm getting:
Code:
IllegalArgumentException occurred while calling setter of wfb.definitions.CountryData.cities, caused by argument type mismatch

caused by query.list(). So, my setter setCities doesn't get an argument of the type List<CityDataInterface> but of the type List<CityData> I suppose - is there any way to check that? Although CityData implements CityDataInterface, it won't match.
But loading a country's capital is working, although in my mapping file, it's of the type CityData and not CityDataInterface.
So, why does it work with a single City but not with a list of cities and how to solve that issue?

It's the first time I'm working with hibernate therefor don't be mad about possibly stupid mistakes. I've spent hours reading documentations and searching the net, unfortunately without finding something that helps me with that issue.

I'll gratefully take any advice!


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.