[question] Deleting DataObjects using the PK

From: Laszlo Spoor (lspoor_cayenn..otmail.com)
Date: Sat Mar 01 2003 - 13:56:09 EST

  • Next message: Craig Miskell: "Re: [question] Deleting DataObjects using the PK"

    Hi Guys,

    When building my website, I need to do a delete, based on my PK (this is the
    only unique key in my table). If I add the Id to my DataMap I can delete an
    instance using:

      [..]
      SelectQuery qry = new SelectQuery (Photo.class);

      Expression qualifier
        = ExpressionFactory.binaryPathExp(Expression.EQUAL_TO, "id", "320");

      qry.andQualifier(qualifier);

      Photo fto = (Photo)mContext.performQuery(qry).get(0);

      mContext.deleteObject(fto);
      mContext.commitChanges(Level.WARN);
      [..]

    However, I am in trouble, whenever I try to create a Photo object, using the
    code:

        [..]
        Foto foto = (Foto) mContext.createAndRegisterNewObject("Foto");
        foto.setToFotoType(fototype);
        foto.setBestandsnaam("MyFileName.jpg");
        foto.setUrlFoto("tmp");
        foto.setUrlThumbnail("tmp");
        mContext.commitChanges(Level.WARN);
        [..]

    WARN QueryLogger: --- will run 1 query.

    WARN QueryLogger: INSERT INTO dgw_fotos (id, fte_id, bestandsnaam,
    url_thumbnail, url_foto, id) VALUES (?, ?, ?, ?, ?, ?) [params: NULL, 2,
    'k7s5a.jpg', 'tmp', 'tmp', NULL]

    WARN QueryLogger: *** error.

    java.sql.SQLException: General error: Column 'id' specified twice

            at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)

            at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)

            at com.mysql.jdbc.Connection.execSQL(Unknown Source)

            at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown Source)

            at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown Source)

            at org.objectstyle.cayenne.access.DataNode.runUpdate(DataNode.java:412)

            at
    org.objectstyle.cayenne.access.DataNode.performQueries(DataNode.java:280)

            at
    org.objectstyle.cayenne.access.DataDomain.performQueries(DataDomain.java:427)

            at
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:873)

            at dgw.handler.CpxFtoHandler.insertPhotoInDb(CpxFtoHandler.java:321)

            at dgw.handler.CpxFtoHandler.save(CpxFtoHandler.java:375)

            at
    dgw.controller.ImgCpxFtoAddController.save(ImgCpxFtoAddController.java:41)

            at _ImgCpxFtoAddAction._jspService(ImgCpxFtoAddAction.jsp:25)

            at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:139)

            at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:348)

            at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:487)

            at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:391)

            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

            at
    com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)

            at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:292)

            at
    com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:606)

            at
    com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:312)

            at
    com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:779)

            at
    com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)

            at
    com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)

            at
    com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)

            at java.lang.Thread.run(Thread.java:536)

    WARN DefaultOperationObserver: query exception

    java.sql.SQLException: General error: Column 'id' specified twice

            at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)

            at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)

            at com.mysql.jdbc.Connection.execSQL(Unknown Source)

            at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown Source)

            at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown Source)

            at org.objectstyle.cayenne.access.DataNode.runUpdate(DataNode.java:412)

            at
    org.objectstyle.cayenne.access.DataNode.performQueries(DataNode.java:280)

            at
    org.objectstyle.cayenne.access.DataDomain.performQueries(DataDomain.java:427)

            at
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:873)

            at dgw.handler.CpxFtoHandler.insertPhotoInDb(CpxFtoHandler.java:321)

            at dgw.handler.CpxFtoHandler.save(CpxFtoHandler.java:375)

            at
    dgw.controller.ImgCpxFtoAddController.save(ImgCpxFtoAddController.java:41)

            at _ImgCpxFtoAddAction._jspService(ImgCpxFtoAddAction.jsp:25)

            at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:139)

            at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:348)

            at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:487)

            at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:391)

            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

            at
    com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)

            at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:292)

            at
    com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:606)

            at
    com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:312)

            at
    com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:779)

            at
    com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)

            at
    com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)

            at
    com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)

            at java.lang.Thread.run(Thread.java:536)

    WARN QueryLogger: *** error.

    org.objectstyle.cayenne.CayenneRuntimeException: Raising from query
    exception.

            at
    org.objectstyle.cayenne.access.util.ContextCommitObserver.nextQueryException(ContextCommitObserver.java:183)

            at
    org.objectstyle.cayenne.access.DataNode.performQueries(DataNode.java:288)

            at
    org.objectstyle.cayenne.access.DataDomain.performQueries(DataDomain.java:427)

            at
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:873)

            at dgw.handler.CpxFtoHandler.insertPhotoInDb(CpxFtoHandler.java:321)

            at dgw.handler.CpxFtoHandler.save(CpxFtoHandler.java:375)

            at
    dgw.controller.ImgCpxFtoAddController.save(ImgCpxFtoAddController.java:41)

            at _ImgCpxFtoAddAction._jspService(ImgCpxFtoAddAction.jsp:25)

            at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:139)

            at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:348)

            at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:487)

            at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:391)

            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

            at
    com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)

            at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:292)

            at
    com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:606)

            at
    com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:312)

            at
    com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:779)

            at
    com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)

            at
    com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)

            at
    com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)

            at java.lang.Thread.run(Thread.java:536)

    Caused by: java.sql.SQLException: General error: Column 'id' specified twice

            at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)

            at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)

            at com.mysql.jdbc.Connection.execSQL(Unknown Source)

            at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown Source)

            at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown Source)

            at org.objectstyle.cayenne.access.DataNode.runUpdate(DataNode.java:412)

            at
    org.objectstyle.cayenne.access.DataNode.performQueries(DataNode.java:280)

            ... 20 more

    WARN QueryLogger: *** transaction rolled back.

    WARN DefaultOperationObserver: global exception

    org.objectstyle.cayenne.CayenneRuntimeException: Raising from query
    exception.

            at
    org.objectstyle.cayenne.access.util.ContextCommitObserver.nextQueryException(ContextCommitObserver.java:183)

            at
    org.objectstyle.cayenne.access.DataNode.performQueries(DataNode.java:288)

            at
    org.objectstyle.cayenne.access.DataDomain.performQueries(DataDomain.java:427)

            at
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:873)

            at dgw.handler.CpxFtoHandler.insertPhotoInDb(CpxFtoHandler.java:321)

            at dgw.handler.CpxFtoHandler.save(CpxFtoHandler.java:375)

            at
    dgw.controller.ImgCpxFtoAddController.save(ImgCpxFtoAddController.java:41)

            at _ImgCpxFtoAddAction._jspService(ImgCpxFtoAddAction.jsp:25)

            at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:139)

            at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:348)

            at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:487)

            at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:391)

            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

            at
    com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)

            at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:292)

            at
    com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:606)

            at
    com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:312)

            at
    com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:779)

            at
    com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)

            at
    com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)

            at
    com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)

            at java.lang.Thread.run(Thread.java:536)

    Caused by: java.sql.SQLException: General error: Column 'id' specified twice

            at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)

            at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)

            at com.mysql.jdbc.Connection.execSQL(Unknown Source)

            at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown Source)

            at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown Source)

            at org.objectstyle.cayenne.access.DataNode.runUpdate(DataNode.java:412)

            at
    org.objectstyle.cayenne.access.DataNode.performQueries(DataNode.java:280)

            ... 20 more

    Debugger disconnected from local process.
    Process exited with exit code 0.

    I am probably doing something wrong, but I can't see what. Can anyone give
    me a tip?

    Thanks in advance, Laszlo Spoor

    _________________________________________________________________
    MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
    http://join.msn.com/?page=features/virus



    This archive was generated by hypermail 2.0.0 : Sat Mar 01 2003 - 13:59:02 EST