db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Stenerud <k...@zergsoft.com>
Subject Is this a Torque bug or a problem in my code?
Date Thu, 22 Jan 2004 09:24:29 GMT
Can someone please tell me if the following is a Torque bug or a problem in my code?

I'm building a system that allows multilingual information for a restaurant.
The Restaurant object can have RestaurantInformation objects associated with it.
The RestaurantInformation object has a composite key made from a restaurant ID and a 2-character
language field (there are 2 columns with primaryKey="true").


In my code, I fill out a new Restaurant object, then I fill out a new RestaurantInformation
object.
Finally, I add the RestaurantInformation object to the Restaurant object and call save on
the Restaurant.
At this point, I get an exception thrown from within BaseRestaurantInformation.
The generated code at the point of exception looks like this:

    public void setPrimaryKey(ObjectKey key) throws TorqueException
    {
        SimpleKey[] keys = (SimpleKey[]) key.getValue();    // <-- Line 650
        SimpleKey tmpKey = null;
                      setRestaurantNo(((NumberKey)keys[0]).intValue());
                        setLanguage(keys[1].toString());
              }



schema file snippet:
==========================================================================
<database
    name="restauranteur"
    defaultJavaNamingMethod="javaname"
    defaultIdMethod="idbroker">
...
  <table name="Restaurant" description="Representation of a single restaurant">
    <column
        name="restaurantId"
        required="true"
        primaryKey="true"
        type="INTEGER"
        description="Unique ID"/>
    <column
        name="stringIdentifier"
        required="true"
        type="VARCHAR"
        size="40"
        description="String-based identifier"/>
    <column
        name="phoneNumber"
        required="true"
        type="VARCHAR"
        size="20"
        description="Phone number"/>
    <column
        name="faxNumber"
        required="true"
        type="VARCHAR"
        size="20"
        description="Fax number"/>
    <unique>
      <unique-column name="stringIdentifier"/>
    </unique>
  </table>
  <table name="RestaurantInformation" description="Language specific information for a
restaurant">
    <column
        name="restaurantNo"
        required="true"
        primaryKey="true"
        type="INTEGER"
        description="Foreign Key Restaurant Id"/>
    <column
        name="language"
        required="true"
        primaryKey="true"
        type="VARCHAR"
        size="2"
        description="Language code"/>
    <column
        name="name"
        required="true"
        type="VARCHAR"
        size="40"
        description="Name"/>
    <column
        name="hours"
        required="true"
        type="VARCHAR"
        size="60"
        description="Hours of operation"/>
    <column
        name="location"
        required="true"
        type="VARCHAR"
        size="100"
        description="Location"/>
    <foreign-key foreignTable="Restaurant">
      <reference
        local="restaurantNo"
        foreign="restaurantId"/>
    </foreign-key>
  </table>
...
</database>
==========================================================================


build.properties snippet:
==========================================================================
torque.database = mysql
torque.addGetByNameMethod = true
torque.addIntakeRetrievable = false
torque.addSaveMethod = true
torque.addTimeStamp = true
torque.basePrefix = Base
torque.complexObjectModel = true
torque.useClasspath = true
torque.useManagers = false
==========================================================================


Offending code snippet:
==========================================================================
        Restaurant restaurant = new Restaurant();
        restaurant.setStringIdentifier("test");
        restaurant.setPhoneNumber("000");
        restaurant.setFaxNumber("000");

        RestaurantInformation info = new RestaurantInformation();
        info.setLanguage("en");
        info.setName("test");
        info.setHours("24/7");
        info.setLocation("The Moon");
        info.setParking("Anywhere");
        info.setDirections("Head towards the moon");
        info.setPortalText("Portal text");
        info.setTopPageText("top page text");

        restaurant.addRestaurantInformation(info);
        restaurant.save();   // <--- Line 27 in RestaurantPersistence.java
==========================================================================


Partial stack trace:
==========================================================================
Caused by: java.lang.ClassCastException
        at com.somewhere.restauranteur.data.BaseRestaurantInformation.setPrimaryKey(BaseRestaurantInformation.java:650)
        at com.somewhere.restauranteur.data.BaseRestaurantInformationPeer.doInsert(BaseRestaurantInformationPeer.java:593)
        at com.somewhere.restauranteur.data.BaseRestaurantInformation.save(BaseRestaurantInformation.java:624)
        at com.somewhere.restauranteur.data.BaseRestaurant.save(BaseRestaurant.java:1251)
        at com.somewhere.restauranteur.data.BaseRestaurant.save(BaseRestaurant.java:1191)
        at com.somewhere.restauranteur.data.BaseRestaurant.save(BaseRestaurant.java:1171)
        at com.somewhere.restauranteur.data.RestaurantPersistence.addFakeRestaurant(RestaurantPersistence.java:27)
        ...
==========================================================================


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message