Incorrect Insert-Statement Order After Deleting All Objects

From: Peter Karich (peatha..ahoo.de)
Date: Thu Dec 14 2006 - 08:49:34 EST

  • Next message: Tore Halset: "Re: Represesntation of database NULL as something else than Java null pointer"

    Hallo,

    After creating the database schema I can successfully insert objects.
    But if I will do the schema creation (DbGenerator.runGenerator) after I
    already have some objects in the database (so the user can change the
    mapping!) I will get an error [1], the mapping is in [2].
    To avoid possible caching I deleted all the database, before I overwrite
    the schema like:

    Collection rooms = getAllRooms();
    getContext().deleteObjects(rooms);
    getContext().commitChanges();

    Collection tis = getAllTimeIntervals();
    getContext().deleteObjects(tis);
    getContext().commitChanges();

    Collection subjects = getAllSubjects();
    getContext().deleteObjects(subjects);
    getContext().getEntityResolver().clearCache();
    getContext().getObjectStore().getDataRowCache().clear();
    getContext().commitChanges();

    The problem is (I think) that cayenne think there is a Subject with ID =
    349. But there is no subject with this ID! It WAS removed from the
    database with the schemacreation and with the deleteObjects to make it
    secure...
    Maybe cayenne calculated an incorrect order of the statements, because
    sometimes it works sometimes not?
    What is wrong?
    What else should I remove?
    I use Cayenne 1.2.1 and derby 10.2.1.1

    Thank you in advance, Peter Karich.

    [1] INFO QueryLogger: INSERT INTO TIMEINTERVAL (DURATION_TIME, ROOM_FK,
    START_TIME, SUBJECT_FK, TIMEINTERVAL_ID) VALUES (?, ?, ?, ?, ?)
    INFO QueryLogger: [bind: 30, 236, 427, 349, 200]
    INFO QueryLogger: *** error.
    java.sql.SQLException: INSERT on table 'TIMEINTERVAL' caused a violation
    of foreign key constraint 'SQL061214022418000' for key (349). The
    statement has been rolled back.
             at
    org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown
    Source)
             at
    org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
             at
    org.apache.derby.client.am.PreparedStatement.executeUpdate(Unknown Source)
             at
    org.objectstyle.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(BatchAction.java:224)
             at
    org.objectstyle.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:117)
             at
    org.objectstyle.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:95)
             at
    org.objectstyle.cayenne.access.DataNode.performQueries(DataNode.java:309)
             at
    org.objectstyle.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:255)
             at
    org.objectstyle.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:177)
             at
    org.objectstyle.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:830)
             at
    org.objectstyle.cayenne.access.DataDomain$2.transform(DataDomain.java:801)
             at
    org.objectstyle.cayenne.access.DataDomain.runInTransaction(DataDomain.java:856)
             at
    org.objectstyle.cayenne.access.DataDomain.onSync(DataDomain.java:798)
             at
    org.objectstyle.cayenne.access.DataContext.flushToParent(DataContext.java:1261)
             at
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:1165)

    [2] <?xml version="1.0" encoding="utf-8"?>
    <data-map project-version="1.1">
            <property name="defaultLockType" value="optimistic"/>
            <property name="defaultPackage" value="de.gstpl.data"/>
            <property name="defaultSuperclass" value="Timetable"/>
            <property name="clientSupported" value="true"/>
            <db-entity name="DB_PROPERTIES">
                    <db-attribute name="DATA_MAP" type="LONGVARCHAR" isMandatory="true"/>
                    <db-attribute name="DAY_DURATION" type="INTEGER" isMandatory="true"/>
                    <db-attribute name="DAY_NO" type="INTEGER" isMandatory="true"/>
                    <db-attribute name="DAY_START" type="INTEGER" isMandatory="true"/>
                    <db-attribute name="DB_PROPERTIES_ID" type="INTEGER"
    isPrimaryKey="true" isMandatory="true"/>
                    <db-attribute name="DEFAULT_ROOM_CAPACITY" type="INTEGER"
    isMandatory="true"/>
                    <db-attribute name="LAST_MAP_UPDATE" type="DATE" isMandatory="true"/>
                    <db-attribute name="MIN_TIME_INTERVAL" type="INTEGER" isMandatory="true"/>
                    <db-attribute name="USEFUL_TIME_INTERVAL" type="INTEGER"
    isMandatory="true"/>
                    <db-attribute name="VERSION" type="VARCHAR" isMandatory="true"
    length="10"/>
            </db-entity>
            <db-entity name="GROUPY">
                    <db-attribute name="GROUPY_ID" type="INTEGER" isPrimaryKey="true"
    isMandatory="true"/>
                    <db-attribute name="NAME" type="VARCHAR" isMandatory="true" length="50"/>
            </db-entity>
            <db-entity name="PERSON">
                    <db-attribute name="LOGIN" type="VARCHAR" length="50"/>
                    <db-attribute name="NAME" type="VARCHAR" isMandatory="true" length="50"/>
                    <db-attribute name="PERSON_ID" type="INTEGER" isPrimaryKey="true"
    isMandatory="true"/>
            </db-entity>
            <db-entity name="PERSON_SUBJECT">
                    <db-attribute name="PERSON_FK" type="INTEGER" isMandatory="true"/>
                    <db-attribute name="PERSON_SUBJECT_ID" type="INTEGER"
    isPrimaryKey="true" isMandatory="true"/>
                    <db-attribute name="SUBJECT_FK" type="INTEGER" isMandatory="true"/>
            </db-entity>
            <db-entity name="ROOM">
                    <db-attribute name="CAPACITY" type="INTEGER"/>
                    <db-attribute name="DESCRIPTION" type="VARCHAR" length="512"/>
                    <db-attribute name="DISTANCE" type="INTEGER"/>
                    <db-attribute name="KIND_U" type="VARCHAR" length="15"/>
                    <db-attribute name="LOCATION_U" type="VARCHAR" length="15"/>
                    <db-attribute name="NAME" type="VARCHAR" isMandatory="true" length="50"/>
                    <db-attribute name="ROOM_ID" type="INTEGER" isPrimaryKey="true"
    isMandatory="true"/>
            </db-entity>
            <db-entity name="SUBJECT">
                    <db-attribute name="DESCRIPTION" type="VARCHAR" length="512"/>
                    <db-attribute name="NAME" type="VARCHAR" isMandatory="true" length="50"/>
                    <db-attribute name="SEMESTER_U" type="INTEGER"/>
                    <db-attribute name="SUBJECT_ID" type="INTEGER" isPrimaryKey="true"
    isMandatory="true"/>
            </db-entity>
            <db-entity name="TIMEINTERVAL">
                    <db-attribute name="DURATION_TIME" type="INTEGER" isMandatory="true"/>
                    <db-attribute name="ROOM_FK" type="INTEGER"/>
                    <db-attribute name="START_TIME" type="INTEGER"/>
                    <db-attribute name="SUBJECT_FK" type="INTEGER"/>
                    <db-attribute name="TIMEINTERVAL_ID" type="INTEGER"
    isPrimaryKey="true" isMandatory="true"/>
            </db-entity>
            <db-entity name="VISIBLE_TABLE">
                    <db-attribute name="COLUMN_NAME" type="VARCHAR" isMandatory="true"
    length="50"/>
                    <db-attribute name="GROUP_FK" type="INTEGER" isMandatory="true"/>
                    <db-attribute name="TABLE_NAME" type="VARCHAR" isMandatory="true"
    length="25"/>
                    <db-attribute name="VISIBLE_TABLE_ID" type="INTEGER"
    isPrimaryKey="true" isMandatory="true"/>
            </db-entity>
            <obj-entity name="DBProperties" className="de.gstpl.data.DBProperties"
    clientClassName="DBProperties" lock-type="optimistic"
    dbEntityName="DB_PROPERTIES">
                    <obj-attribute name="dataMap" type="java.lang.String"
    db-attribute-path="DATA_MAP"/>
                    <obj-attribute name="dayDuration" type="java.lang.Integer"
    db-attribute-path="DAY_DURATION"/>
                    <obj-attribute name="dayNo" type="java.lang.Integer"
    db-attribute-path="DAY_NO"/>
                    <obj-attribute name="dayStart" type="java.lang.Integer"
    db-attribute-path="DAY_START"/>
                    <obj-attribute name="defaultRoomCapacity" type="java.lang.Integer"
    db-attribute-path="DEFAULT_ROOM_CAPACITY"/>
                    <obj-attribute name="lastMapUpdate" type="java.util.Date"
    db-attribute-path="LAST_MAP_UPDATE"/>
                    <obj-attribute name="minTimeInterval" type="java.lang.Integer"
    db-attribute-path="MIN_TIME_INTERVAL"/>
                    <obj-attribute name="usefulTimeInterval" type="java.lang.Integer"
    db-attribute-path="USEFUL_TIME_INTERVAL"/>
                    <obj-attribute name="version" type="java.lang.String"
    db-attribute-path="VERSION"/>
            </obj-entity>
            <obj-entity name="Group" className="de.gstpl.data.person.Group"
    clientClassName="Group" lock-type="optimistic" dbEntityName="GROUPY">
                    <obj-attribute name="name" type="java.lang.String"
    db-attribute-path="NAME"/>
            </obj-entity>
            <obj-entity name="Person" className="de.gstpl.data.Person"
    clientClassName="Person" lock-type="optimistic" dbEntityName="PERSON">
                    <obj-attribute name="login" type="java.lang.String"
    db-attribute-path="LOGIN"/>
                    <obj-attribute name="name" type="java.lang.String"
    db-attribute-path="NAME"/>
            </obj-entity>
            <obj-entity name="Room" className="de.gstpl.data.Room"
    clientClassName="Room" lock-type="optimistic" dbEntityName="ROOM">
                    <obj-attribute name="KIND_U" type="java.lang.String"
    db-attribute-path="KIND_U"/>
                    <obj-attribute name="LOCATION_U" type="java.lang.String"
    db-attribute-path="LOCATION_U"/>
                    <obj-attribute name="capacity" type="java.lang.Integer"
    db-attribute-path="CAPACITY"/>
                    <obj-attribute name="description" type="java.lang.String"
    db-attribute-path="DESCRIPTION"/>
                    <obj-attribute name="distance" type="java.lang.Integer"
    db-attribute-path="DISTANCE"/>
                    <obj-attribute name="name" type="java.lang.String"
    db-attribute-path="NAME"/>
            </obj-entity>
            <obj-entity name="Subject" className="de.gstpl.data.Subject"
    clientClassName="Subject" lock-type="optimistic" dbEntityName="SUBJECT">
                    <obj-attribute name="SEMESTER_U" type="java.lang.Integer"
    db-attribute-path="SEMESTER_U"/>
                    <obj-attribute name="description" type="java.lang.String"
    db-attribute-path="DESCRIPTION"/>
                    <obj-attribute name="name" type="java.lang.String"
    db-attribute-path="NAME"/>
            </obj-entity>
            <obj-entity name="TimeInterval" className="de.gstpl.data.TimeInterval"
    clientClassName="TimeInterval" lock-type="optimistic"
    dbEntityName="TIMEINTERVAL" superClassName="de.gstpl.data.TimeableImpl">
                    <obj-attribute name="durationTime" type="java.lang.Integer"
    db-attribute-path="DURATION_TIME"/>
                    <obj-attribute name="startTime" type="java.lang.Integer"
    db-attribute-path="START_TIME"/>
            </obj-entity>
            <obj-entity name="VisibleTable"
    className="de.gstpl.data.person.VisibleTable" lock-type="optimistic"
    dbEntityName="VISIBLE_TABLE">
                    <obj-attribute name="columnName" type="java.lang.String"
    db-attribute-path="COLUMN_NAME"/>
                    <obj-attribute name="tableName" type="java.lang.String"
    db-attribute-path="TABLE_NAME"/>
            </obj-entity>
            <db-relationship name="visibleTables" source="GROUPY"
    target="VISIBLE_TABLE" toMany="true">
                    <db-attribute-pair source="GROUPY_ID" target="GROUP_FK"/>
            </db-relationship>
            <db-relationship name="timeables" source="PERSON"
    target="PERSON_SUBJECT" toMany="true">
                    <db-attribute-pair source="PERSON_ID" target="PERSON_FK"/>
            </db-relationship>
            <db-relationship name="person" source="PERSON_SUBJECT" target="PERSON"
    toMany="false">
                    <db-attribute-pair source="PERSON_FK" target="PERSON_ID"/>
            </db-relationship>
            <db-relationship name="subject" source="PERSON_SUBJECT"
    target="SUBJECT" toMany="false">
                    <db-attribute-pair source="SUBJECT_FK" target="SUBJECT_ID"/>
            </db-relationship>
            <db-relationship name="timeables" source="ROOM" target="TIMEINTERVAL"
    toMany="true">
                    <db-attribute-pair source="ROOM_ID" target="ROOM_FK"/>
            </db-relationship>
            <db-relationship name="persons" source="SUBJECT"
    target="PERSON_SUBJECT" toMany="true">
                    <db-attribute-pair source="SUBJECT_ID" target="SUBJECT_FK"/>
            </db-relationship>
            <db-relationship name="timeables" source="SUBJECT"
    target="TIMEINTERVAL" toMany="true">
                    <db-attribute-pair source="SUBJECT_ID" target="SUBJECT_FK"/>
            </db-relationship>
            <db-relationship name="room" source="TIMEINTERVAL" target="ROOM"
    toMany="false">
                    <db-attribute-pair source="ROOM_FK" target="ROOM_ID"/>
            </db-relationship>
            <db-relationship name="subject" source="TIMEINTERVAL" target="SUBJECT"
    toMany="false">
                    <db-attribute-pair source="SUBJECT_FK" target="SUBJECT_ID"/>
            </db-relationship>
            <db-relationship name="group" source="VISIBLE_TABLE" target="GROUPY"
    toMany="false">
                    <db-attribute-pair source="GROUP_FK" target="GROUPY_ID"/>
            </db-relationship>
            <obj-relationship name="visibleTables" source="Group"
    target="VisibleTable" deleteRule="Cascade"
    db-relationship-path="visibleTables"/>
            <obj-relationship name="timeables" source="Person" target="Subject"
    deleteRule="Nullify" db-relationship-path="timeables.subject"/>
            <obj-relationship name="timeables" source="Room" target="TimeInterval"
    deleteRule="Nullify" db-relationship-path="timeables"/>
            <obj-relationship name="persons" source="Subject" target="Person"
    deleteRule="Nullify" db-relationship-path="persons.person"/>
            <obj-relationship name="timeables" source="Subject"
    target="TimeInterval" deleteRule="Cascade"
    db-relationship-path="timeables"/>
            <obj-relationship name="room" source="TimeInterval" target="Room"
    deleteRule="Nullify" db-relationship-path="room"/>
            <obj-relationship name="subject" source="TimeInterval" target="Subject"
    deleteRule="Nullify" db-relationship-path="subject"/>
            <obj-relationship name="group" source="VisibleTable" target="Group"
    deleteRule="Nullify" db-relationship-path="group"/>
            <query name="Delete"
    factory="org.objectstyle.cayenne.map.SQLTemplateBuilder" root="data-map"
    root-name="GSTPL">
                    <property name="cayenne.GenericSelectQuery.fetchingDataRows"
    value="true"/>
                    <sql><![CDATA[delete from $table]]></sql>
            </query>
            <query name="GetColumnNames"
    factory="org.objectstyle.cayenne.map.SQLTemplateBuilder" root="data-map"
    root-name="GSTPL">
                    <property name="cayenne.GenericSelectQuery.fetchingDataRows"
    value="true"/>
                    <sql><![CDATA[select * from $table where 1=2]]></sql>
            </query>
            <query name="GetTI"
    factory="org.objectstyle.cayenne.map.SQLTemplateBuilder"
    root="obj-entity" root-name="TimeInterval">
                    <sql><![CDATA[select * from TIMEINTERVAL where
             START_TIME = $start and
             DURATION_TIME = $duration and
             ROOM_ID = $roomId and
             SUBJECT_ID = $subjectId]]></sql>
            </query>
            <query name="SelectTable"
    factory="org.objectstyle.cayenne.map.SQLTemplateBuilder" root="data-map"
    root-name="GSTPL">
                    <property name="cayenne.GenericSelectQuery.fetchingDataRows"
    value="true"/>
                    <sql><![CDATA[select * from $table]]></sql>
            </query>
            <query name="SetSchema"
    factory="org.objectstyle.cayenne.map.SQLTemplateBuilder" root="data-map"
    root-name="GSTPL">
                    <property name="cayenne.GenericSelectQuery.fetchingDataRows"
    value="true"/>
                    <sql><![CDATA[set schema $schemaName]]></sql>
            </query>
    </data-map>

            
                    
    ___________________________________________________________
    Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de



    This archive was generated by hypermail 2.0.0 : Thu Dec 14 2006 - 08:49:43 EST