Re: object regsitered in a different DataContext

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Dec 02 2005 - 06:29:48 EST

  • Next message: Todd O'Bryan: "Re: object regsitered in a different DataContext"

    Hi Andrea,

    Take the error message at face value. It means this:

         persona.getDataContext() != CayenneConnection.dataContext

     From your code snip it is not clear why this would happen. A few
    things to check:

    * Is it possible that "connect" is called twice?
    * Do you ever serialize/deserilaize DOTableModel?

    Andrus

    On Dec 2, 2005, at 1:23 PM, 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 - 06:29:51 EST