Strange Problem

From: Lucas Holt (luk..oolishgames.com)
Date: Thu Jul 30 2009 - 16:27:10 EDT

  • Next message: Michael Gentry: "Re: Strange Problem"

    I've got a situation where I need to obtain the primary key. My
    solution was to add a method like so:

    public Byte getOfficeId() {
          return (getObjectId() != null && !getObjectId().isTemporary())
                     ? (Byte)
    getObjectId().getIdSnapshot().get(OFFICE_ID_PK_COLUMN)
                     : null;
    }

    However, sometimes I get back a Byte and other times a Short. I've
    verified this with getClass().getName()

    How exactly does the data type get chosen here? Any suggestions?

    I've thought about just testing for the cases where the type is
    different and converting it, but it seems like this shouldn't be
    happening.

    Here's the table definition:

    CREATE TABLE IF NOT EXISTS `office` ( `office_id` tinyint(3) unsigned
    NOT NULL AUTO_INCREMENT, `country_id` smallint(5) unsigned NOT NULL,
    `company_id` tinyint(3) unsigned NOT NULL, `name` varchar(45) NOT
    NULL, `address` tinytext NOT NULL, PRIMARY KEY (`office_id`), KEY
    `office_country_id` (`country_id`), KEY `office_company`
    (`company_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;

    I'm using Cayenne 2.0.4, MySQL 5.1, mysql-connector-java-5.0.5, and
    java version "1.5.0_19" (os x)

            <db-entity name="office" catalog="prime_pcd2009">
                    <db-attribute name="address" type="VARCHAR" isMandatory="true"
    length="255"/>
                    <db-attribute name="company_id" type="TINYINT" isMandatory="true"/>
                    <db-attribute name="country_id" type="SMALLINT" isMandatory="true"
    length="5"/>
                    <db-attribute name="name" type="VARCHAR" isMandatory="true"
    length="45"/>
                    <db-attribute name="office_id" type="TINYINT" isPrimaryKey="true"
    isGenerated="true" isMandatory="true" length="3"/>
            </db-entity>

    Luke



    This archive was generated by hypermail 2.0.0 : Thu Jul 30 2009 - 16:27:53 EDT