RE: Is manually creating PKs throwing Cayenne off?

From: Fredrik Liden (flide..ranslate.com)
Date: Wed Mar 09 2005 - 18:53:37 EST

  • Next message: Fredrik Liden: "RE: Is manually creating PKs throwing Cayenne off?"

    When I inserted the getPersistenceState() before and after
    context.commitChanges(); it seems the new_budget object is in NEW state
    even after it's been committed. However, the object has been insterted
    into the database. Does anyone have any ideas? Should I use
    setPersistenceState manually? Even though it's not recommended.

    Thanks!

    /Fredrik

    -----Original Message-----
    From: Fredrik Liden
    Sent: Wednesday, March 09, 2005 2:33 PM
    To: cayenne-use..bjectstyle.org
    Subject: Is manually creating PKs throwing Cayenne off?

    Hi,

    I'm creating an object that does not have PK support.
    using the following code.

    DataContext context =
    BasicServletConfiguration.getDefaultContext(request.getSession());
    Budget new_budget
    =(Budget)context.createAndRegisterNewObject(Budget.class);
    new_budget.setObjectId(new ObjectId(Budget.class,"budget_key",project));
    new_budget.setDateCreated(new Date());
    context.commitChanges();

    This works, and an entry is created in the database table.

    But then when I add another object that does have PK support, Cayenne is
    trying to add the previous object (Budget) again. And I get an error
    because the ID already exists.. somehow it's not registering that the
    object has been created. Does anyone know what I'm doing wrong?

    DataContext context =
    BasicServletConfiguration.getDefaultContext(request.getSession());
    Irf new_irf = (Irf)context.createAndRegisterNewObject(Irf.class);
    new_irf.setProjectKey(project);

    new_irf.setDateCreated(new Date());
    DateFormat formatter = new SimpleDateFormat("MM/dd/yy");
    new_irf.setPurchaseOrder(request.getParameter("purchase_order"));
    context.commitChanges();

    Thanks!

    Fredrik



    This archive was generated by hypermail 2.0.0 : Wed Mar 09 2005 - 18:52:55 EST