cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Schoessler <tobias.schoess...@gmail.com>
Subject Re: Strange Problem
Date Thu, 30 Jul 2009 21:29:44 GMT
Lucas, my experience with mysql Autoincrement fields is that you have to map
them as Long. there is some bug in the mysql jdbc driver which returns wrong
meta information types if the field is set to autoincrement and some other
type than BigInt.
See http://lists.mysql.com/java/6383



On Thu, Jul 30, 2009 at 10:43 PM, Michael Gentry <mgentry@masslight.net>wrote:

> You shouldn't need to write your own method to get the office ID.  Add
> the mapping to your ObjEntity by hand and regenerate the Java class
> and it should create a getOfficeId() for you.
>
> mrg
>
>
> On Thu, Jul 30, 2009 at 4:27 PM, Lucas Holt<luke@foolishgames.com> wrote:
> > 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
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message