Is manually creating PKs throwing Cayenne off?

From: Fredrik Liden (flide..ranslate.com)
Date: Wed Mar 09 2005 - 17:32:41 EST

  • Next message: Fredrik Liden: "RE: 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 - 17:31:59 EST