Re: Modeler question for one-to-one logical mapping

From: Michael Amster (mamste..ebeasy.com)
Date: Sun Jul 06 2003 - 00:00:09 EDT

  • Next message: Andrus Adamchik: "Re: Modeler question for one-to-one logical mapping"

    Andrus:

    I changed the toDependentPK to false. I still see the same error. Do
    you want me to delete the whole entry?

    -MA

    On Sat, 2003-07-05 at 20:10, Andrus Adamchik wrote:
    > Hi Michael,
    >
    > Isn't it a "many-to-one", not "one-to-one" relationship? I have a feeling
    > that this is the case.
    >
    > What I would suggest is to uncheck "to dep pk" on RaceDBEntity (see
    > below). "to dep pk" is used for things like join tables, or truly
    > dependent tables, like say "User -> UserAdditionalInfo". Its purpose is to
    > propagate the value of a primary key from the "master" entity to the
    > "dependent" entity. It doesn't seem appropriate in your case.
    >
    > Andrus
    >
    > P.S. Since I knew that the modeler wouldn't normally allow you to check
    > "to dep pk" unless both source and destination attributes are marked as
    > PK, I was surprised to see the model that you have... Well it turned out
    > to be a bug in the modeler. If you create a relationship as "to dep pk",
    > and then change one of its attributes from "PK" to a regular one, "to dep
    > pk" is still checked, and even worse - it becomes disabled.
    >
    > I will fix this bug; in the meantime please manually delete
    > "toDependentPK="true"" piece from your XML.
    >
    >
    >
    >
    >
    > > Hi:
    > >
    > > I have a lookup table which is used as a logical one to one (not in the
    > > cayenne sense of FK). I am having a hard time understanding how to use
    > > the cayenne modeler to get the relationship correct so that I get back
    > > only the lookup value I need. The database tables are as follows:
    > >
    > > CREATE TABLE RaceDBEntity (location VARCHAR(255) NOT NULL, race_date
    > > DATE NOT NULL, race_id INT NOT NULL, race_name VARCHAR(255) NOT NULL,
    > > race_type_id INT NOT
    > > NULL, year VARCHAR(4) NOT NULL, PRIMARY KEY (race_id))
    > >
    > > CREATE TABLE RaceTypeDbEntity (race_type_id INT NOT NULL, type_name
    > > VARCHAR(255) NOT NULL, PRIMARY KEY (race_type_id))
    > >
    > > RaceTypes are just lookups and each race has a single race type. If I
    > > create a RaceTypeDbEntity relation in RaceDbEntity that is to Dep PK,
    > > and in RaceDbEntity to RaceTypeDbEntity that is To Many, I get the
    > > following error when I add a race with the below code:
    > >
    > > Caused by: org.objectstyle.cayenne.CayenneException: [v.1.0b4 June 16
    > > 2003] Error generating PK: More than one row for 'RaceDBEntity'
    > > at
    > > org.objectstyle.cayenne.access.util.PrimaryKeyHelper.createPermIdsForObjEntity(PrimaryKeyHelper.java:200)
    > > at
    > > org.objectstyle.cayenne.access.ContextCommit.createPrimaryKeys(ContextCommit.java:517)
    > > at
    > > org.objectstyle.cayenne.access.ContextCommit.commit(ContextCommit.java:139)
    > > at
    > > org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:732)
    > > ... 42 more
    > > Caused by: java.sql.SQLException: More than one row for 'RaceDBEntity'
    > > at
    > > org.objectstyle.cayenne.dba.mysql.MySQLPkGenerator.getPrimaryKey(MySQLPkGenerator.java:166)
    > > at
    > > org.objectstyle.cayenne.dba.mysql.MySQLPkGenerator.pkFromDatabase(MySQLPkGenerator.java:93)
    > > at
    > > org.objectstyle.cayenne.dba.JdbcPkGenerator.generatePkForDbEntity(JdbcPkGenerator.java:322)
    > > at
    > > org.objectstyle.cayenne.access.util.PrimaryKeyHelper.createPermIdsForObjEntity(PrimaryKeyHelper.java:195)
    > >
    > > code snippet:
    > > BeanUtils.copyProperties(race, raceForm);
    > > RaceType raceType =
    > > LookupDao.loadRaceTypeById(ctxt,raceForm.getRaceType());
    > > race.setToRaceType(raceType);
    > > ctxt.commitChanges(org.apache.log4j.Level.WARN);
    > >
    > > The xml file looks like this:
    > >
    > > <db-entity name="RaceDBEntity">
    > > <db-attribute name="location" type="VARCHAR" isMandatory="true"
    > > length="255"/>
    > > <db-attribute name="race_date" type="DATE" isMandatory="true"/>
    > > <db-attribute name="race_id" type="INTEGER" isPrimaryKey="true"
    > > isMandatory="true"/>
    > > <db-attribute name="race_name" type="VARCHAR" isMandatory="true"
    > > length="255"/>
    > > <db-attribute name="race_type_id" type="INTEGER"
    > > isMandatory="true"/>
    > > <db-attribute name="year" type="VARCHAR" isMandatory="true"
    > > length="4"/> </db-entity>
    > > <db-entity name="RaceTypeDbEntity">
    > > <db-attribute name="race_type_id" type="INTEGER"
    > > isPrimaryKey="true" isMandatory="true"/>
    > > <db-attribute name="type_name" type="VARCHAR" isMandatory="true"
    > > length="255"/>
    > > </db-entity>
    > >
    > > .....
    > >
    > > <db-relationship name="toRace" source="RaceTypeDbEntity"
    > > target="RaceDBEntity" toDependentPK="false" toMany="true">
    > > <db-attribute-pair source="race_type_id" target="race_type_id"/>
    > > </db-relationship>
    > > <db-relationship name="toRaceType" source="RaceDBEntity"
    > > target="RaceTypeDbEntity" toDependentPK="true" toMany="false">
    > > <db-attribute-pair source="race_type_id" target="race_type_id"/>
    > > </db-relationship>
    > >
    > > Any clue as to how to get this to work is greatly appreciated. I have
    > > the many-to-many situations working fine based on the example in the
    > > tutorial.
    > >
    > > -MA
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Sat Jul 05 2003 - 23:59:52 EDT