Re: flattened relations intermediate table records not deleted with cascade

From: Gritsenko Dmitry (dim..kreative.com)
Date: Wed Feb 02 2005 - 05:09:26 EST

  • Next message: Andrus Adamchik: "Re: Scalar Types"

    Hi Andrus and all willing to help out,

    We have got a shema of 3 tables:

    assessment
    question
    criteria
    and a linking table assessment_result (linking 3 above tables) that we have
    flattened.

    The java code and xml mapping to follow, but as well as the query log.
    In 2 words the problem is: while inserting the flattened table data
    assessment id turns out to be NULL. Please, HELP !!!

    Query log:
    ===================================

    INFO [http8080-Processor4 02-02 12:07:06] QueryLogger: INSERT INTO
    assessment_result (ID, assessment_id, criteria_id, q
    uestion_id) VALUES (?, ?, ?, ?)
    INFO [http8080-Processor4 02-02 12:07:06] QueryLogger: [bind: 360, NULL, 1,
    1]
    INFO [http8080-Processor4 02-02 12:07:06] QueryLogger: *** error.
    java.sql.SQLException: General error, message from server: "Column
    'assessment_id' cannot be null"
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1962)
            at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163)
            at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1257)
            at com.mysql.jdbc.Connection.execSQL(Connection.java:2242)
            at
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1677)
            at
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1524)
            at
    org.objectstyle.cayenne.access.DataNode.runBatchUpdateAsIndividualQueries(Da
    taNode.java:593)
            at
    org.objectstyle.cayenne.access.DataNode.runBatchUpdate(DataNode.java:495)
            at
    org.objectstyle.cayenne.access.DataNode.performQueries(DataNode.java:353)
            at
    org.objectstyle.cayenne.access.ContextCommit.commit(ContextCommit.java:192)
            at
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:12
    66)
            at
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:12
    36)
            at
    com.ekreative.self.assessment.actions.SelfAssessmentAction.execute(SelfAsses
    smentAction.java:66)
            at
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces
    sor.java:484)
            at
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
            at
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
            at
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
    FilterChain.java:247)
            at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
    ain.java:193)
            at
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
    va:256)
            at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:643)
            at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
            at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
            at
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
    va:191)
            at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:643)
            at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
            at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
            at
    org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
            at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180
    )
            at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:643)
            at
    org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
    java:171)
            at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:641)
            at
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172
    )
            at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:641)
            at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
            at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
            at
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
    :174)
            at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:643)
            at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
            at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
            at
    org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
            at
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
            at
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
    ction(Http11Protocol.java:549)
            at
    org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
            at
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
    a:666)
            at java.lang.Thread.run(Thread.java:536)

    Java code:
    ===================================
             Assessment assessment =
    (Assessment)ctxt.createAndRegisterNewObject(Assessment.class);
             assessment.setAssessmentOwner(null);

             SelfAssessmentBean[] selfAssessmentBeans =
    assessmentForm.getSelfAssessmentBeans();

               for (int i = 0; i < selfAssessmentBeans.length; i++) {
                  Question question =
    (Question)DataObjectUtils.objectForPK(ctxt, Question.class,
    selfAssessmentBeans[i].getQuestionId());
                  Criteria criteria =
    (Criteria)DataObjectUtils.objectForPK(ctxt, Criteria.class,
    selfAssessmentBeans[i].getCriteriaId());
                  question.addToQuestionCriteria(criteria);
                  assessment.addToAssessmentQuestions(question);
               }

    XML mapping:
    =================================

    <?xml version="1.0" encoding="utf-8"?>
    <data-map project-version="1.1">

        <!-- ========== Db-entity Configuration
    ================================ -->
        <db-entity name="user" catalog="bsa">
            <db-attribute name="ID" type="BIGINT" isPrimaryKey="true"
    isMandatory="true" length="20"/>
            <db-attribute name="login" type="VARCHAR" isMandatory="true"
    length="40"/>
            <db-attribute name="password" type="VARCHAR" isMandatory="true"
    length="10"/>
        </db-entity>
        <db-entity name="criteria" catalog="bsa">
            <db-attribute name="ID" type="BIGINT" isPrimaryKey="true"
    isMandatory="true" length="20"/>
            <db-attribute name="name" type="VARCHAR" length="255"/>
            <db-attribute name="value" type="SMALLINT" length="6"/>
        </db-entity>
        <db-entity name="question" catalog="bsa">
            <db-attribute name="ID" type="BIGINT" isPrimaryKey="true"
    isMandatory="true" length="20"/>
            <db-attribute name="number" type="SMALLINT" length="6"/>
            <db-attribute name="value" type="LONGVARCHAR" length="65535"/>
        </db-entity>
        <db-entity name="assessment" catalog="bsa">
            <db-attribute name="ID" type="BIGINT" isPrimaryKey="true"
    isMandatory="true" length="20"/>
            <db-attribute name="development_actions" type="LONGVARCHAR"
    length="16277215"/>
            <db-attribute name="owner_id" type="BIGINT" isMandatory="true"
    length="20"/>
            <db-attribute name="strength_actions" type="LONGVARCHAR"
    length="16277215"/>
            <db-attribute name="user_id" type="BIGINT" length="20"/>
        </db-entity>
        <db-entity name="assessment_result" catalog="bsa">
            <db-attribute name="ID" type="BIGINT" isPrimaryKey="true"
    isMandatory="true" length="20"/>
            <db-attribute name="assessment_id" type="BIGINT" isMandatory="true"
    length="20"/>
            <db-attribute name="criteria_id" type="BIGINT" isMandatory="true"
    length="20"/>
            <db-attribute name="question_id" type="BIGINT" isMandatory="true"
    length="20"/>
        </db-entity>

        <!-- ========== Obj-entity Configuration
    ================================ -->
        <obj-entity name="User" className="persistence.User"
    dbEntityName="user">
            <obj-attribute name="login" type="java.lang.String"
    db-attribute-path="login"/>
            <obj-attribute name="password" type="java.lang.String"
    db-attribute-path="password"/>
        </obj-entity>
        <obj-entity name="Criteria" className="persistence.Criteria"
    dbEntityName="criteria">
            <obj-attribute name="name" type="java.lang.String"
    db-attribute-path="name"/>
            <obj-attribute name="value" type="java.lang.Short"
    db-attribute-path="value"/>
        </obj-entity>
        <obj-entity name="Question" className="persistence.Question"
    dbEntityName="question">
            <obj-attribute name="number" type="java.lang.Short"
    db-attribute-path="number"/>
            <obj-attribute name="value" type="java.lang.String"
    db-attribute-path="value"/>
        </obj-entity>
        <obj-entity name="Assessment" className="persistence.Assessment"
    dbEntityName="assessment">
            <obj-attribute name="developmentActions" type="java.lang.String"
    db-attribute-path="development_actions"/>
            <obj-attribute name="strengthActions" type="java.lang.String"
    db-attribute-path="strength_actions"/>
        </obj-entity>

        <!-- ========== Db-relationship Configuration
    ================================ -->
        <db-relationship name="userAssessments" source="user"
    target="assessment" toMany="true">
            <db-attribute-pair source="ID" target="user_id"/>
        </db-relationship>
        <db-relationship name="assessmentUser" source="assessment" target="user"
    toMany="false">
            <db-attribute-pair source="user_id" target="ID"/>
        </db-relationship>
        <db-relationship name="ownerAssessments" source="user"
    target="assessment" toMany="true">
            <db-attribute-pair source="ID" target="owner_id"/>
        </db-relationship>
        <db-relationship name="assessmentOwner" source="assessment"
    target="user" toMany="false">
            <db-attribute-pair source="owner_id" target="ID"/>
        </db-relationship>
        <db-relationship name="assessmentAssessmentResults" source="assessment"
    target="assessment_result" toMany="true">
            <db-attribute-pair source="ID" target="assessment_id"/>
        </db-relationship>
        <db-relationship name="assessmentResultToAssessment"
    source="assessment_result" target="assessment" toMany="false">
            <db-attribute-pair source="assessment_id" target="ID"/>
        </db-relationship>
        <db-relationship name="assessmentResultToQuestion"
    source="assessment_result" target="question" toMany="false">
            <db-attribute-pair source="question_id" target="ID"/>
        </db-relationship>
        <db-relationship name="questionAssessmentResults" source="question"
    target="assessment_result" toMany="true">
            <db-attribute-pair source="ID" target="question_id"/>
        </db-relationship>
        <db-relationship name="assessmentResultToCriteria"
    source="assessment_result" target="criteria" toMany="false">
            <db-attribute-pair source="criteria_id" target="ID"/>
        </db-relationship>
        <db-relationship name="criteriaAssessmentResults" source="criteria"
    target="assessment_result" toMany="true">
            <db-attribute-pair source="ID" target="criteria_id"/>
        </db-relationship>

        <!-- ========== Obj-relationship Configuration
    ================================ -->
        <obj-relationship name="userAssessments" source="User"
    target="Assessment" db-relationship-path="userAssessments"/>
        <obj-relationship name="assessmentUser" source="Assessment"
    target="User" db-relationship-path="assessmentUser"/>
        <obj-relationship name="ownerAssessments" source="User"
    target="Assessment" db-relationship-path="ownerAssessments"/>
        <obj-relationship name="assessmentOwner" source="Assessment"
    target="User" db-relationship-path="assessmentOwner"/>
        <obj-relationship name="assessmentQuestions" source="Assessment"
    target="Question"
    db-relationship-path="assessmentAssessmentResults.assessmentResultToQuestion
    "/>
        <obj-relationship name="questionAssessments" source="Question"
    target="Assessment"
    db-relationship-path="questionAssessmentResults.assessmentResultToAssessment
    "/>
        <obj-relationship name="questionCriteria" source="Question"
    target="Criteria"
    db-relationship-path="questionAssessmentResults.assessmentResultToCriteria"/
    >
        <obj-relationship name="criteriaQuestion" source="Criteria"
    target="Question"
    db-relationship-path="criteriaAssessmentResults.assessmentResultToQuestion"/
    >

    </data-map>



    This archive was generated by hypermail 2.0.0 : Wed Feb 02 2005 - 05:09:18 EST