Re: object regsitered in a different DataContext

From: Mike Kienenberger (mkienen..mail.com)
Date: Fri Dec 02 2005 - 09:42:51 EST

  • Next message: Andrus Adamchik: "Re: object regsitered in a different DataContext"

    Another alternative is to do this:

             persona.getDataContext().deleteObject(persona); // here
    persona is not null
             persona.getDataContext().commitChanges();

    On 12/2/05, Todd O'Bryan <toddobrya..ac.com> wrote:
    > Basically, persona is from a different DataContext, so
    > CayenneConnection.dataContext is having trouble deleting it. You can use
    >
    > CayenneConnection.dataContext.localObjects(Collections.singletonList(persona))
    >
    > to get a copy of the object local to this DataContext which it should be
    > possible to delete.
    >
    > Todd
    >
    >
    > On Dec 2, 2005, at 5:23 AM, Andrea Borgogelli Avveduti wrote:
    >
    >
    > Hello boys
    >
    > I'm a newbie, and I'd like to simply delete a DataOject in Cayenne. I have
    > tried this code:
    >
    > PersonaFisica persona = (PersonaFisica) ( (DOTableModel)
    > jPanelTable.table.getModel()).getDataObject(selRows[0]);
    >
    > CayenneConnection.dataContext.deleteObject(persona); //
    > here persona is not null
    > CayenneConnection.dataContext.commitChanges();
    > .....
    >
    >
    > But I got the following error:
    >
    >
    > org.objectstyle.cayenne.CayenneRuntimeException: [v.1.2M8
    > November 24005] Attempt to delete object regsitered in a different
    > DataContext
    >
    >
    > What does it mean ? Could someone help me please ? Any advices will be
    > useful.
    >
    > For connection I use a class like this:
    >
    >
    > public class CayenneConnection {
    >
    > public static DataContext dataContext;
    > public static DataView dataView;
    > public static Configuration conf;
    >
    > ......
    >
    >
    > /**
    > * connect
    > */
    > public static void connect() {
    > init();
    > try {
    > dataContext = DataContext.createDataContext();
    > }
    > catch (Exception ex) {
    > ex.printStackTrace();
    >
    > JOptionPane.showMessageDialog(
    > null,
    > ex.getMessage(),
    > "Connection Error",
    > JOptionPane.ERROR_MESSAGE);
    > return;
    > }
    > }
    >
    > /**
    > * loadDataView
    > */
    > public static void loadConfig() {
    > dataView = new DataView();
    > dataView.setEntityResolver(dataContext.getEntityResolver());
    > try {
    > conf.loadDataView(dataView);
    > }
    > catch (IOException ioex) {
    > ioex.printStackTrace();
    > throw new CayenneRuntimeException("Error loading DataView", ioex);
    > }
    > }
    >
    > /**
    > * init
    > */
    > public static void init() {
    > DataSource dataSource1 = null;
    > DataSource dataSource2 = null;
    > try {
    > dataSource1 = new PoolManager(Config.defaultFirebirdDriver,
    >
    > Config.defaultFirebirdUrlPrefix + Config.firebirdUrl +
    > Config.defaultDbAnagrafica,
    > 1,
    > 5,
    > Config.firebirdUser,
    >
    > Config.firebirdPassword);
    >
    > dataSource2 = new PoolManager(Config.defaultFirebirdDriver,
    >
    > Config.defaultFirebirdUrlPrefix + Config.firebirdUrl +
    > Config.defaultDbPaghe,
    > 1,
    > 5,
    > Config.firebirdUser,
    >
    > Config.firebirdPassword);
    > }
    > catch (SQLException ex) {
    > }
    > conf = Configuration.getSharedConfiguration();
    > DataDomain domain = conf2.getDomain();
    > DataNode node1 = domain.getNode("MyDomainNode");
    > DataNode node2 = domain.getNode("MyDomainNode2");
    > node1.setDataSource(dataSource1);
    > node2.setDataSource(dataSource2);
    > }
    >
    > }
    >
    > Thank u in advance and greetings from Italy.
    >
    > Andrea
    >
    >



    This archive was generated by hypermail 2.0.0 : Fri Dec 02 2005 - 09:42:53 EST