Well your code works. Great.
System.out.println("datacontext = " + CayenneConnection.dataContext.toString());
System.out.println("datacontext2 = " + persona.getDataContext().toString());
persona.getDataContext().deleteObject(persona);
persona.getDataContext().commitChanges();
But here the console output
datacontext = org.objectstyle.cayenne.access.DataContext@14340bb
datacontext2 = org.objectstyle.cayenne.access.DataContext@14340bb
The DataContexts are the same, aren't they ?
So where could be the root of the problem ?
Here the class I use:
public class CayenneConnection {
public static DataContext dataContext;
public static DataView dataView;
public static DefaultConfiguration conf;
public static Configuration conf2;
public CayenneConnection() {
}
/**
* disconnect
*/
public static void disconnect() {
dataContext.getParentDataDomain().shutdown();
dataContext = null;
}
/**
* isConnected
*/
public static boolean isConnected() {
if (dataContext != null) {
return true;
}
else {
return false;
}
}
/**
* connect
*/
public static void connect() {
init(); // datasource and datanode inizializations
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 {
conf2.loadDataView(dataView);
}
catch (IOException ioex) {
ioex.printStackTrace();
throw new CayenneRuntimeException("Error loading DataView", ioex);
}
}
.................
From: "Andrea Borgogelli Avveduti" <borgogell..otmail.com>
Reply-To: cayenne-user@objectstyle.org
To: cayenne-user@objectstyle.org
Subject: Re: object regsitered in a different DataContext
Date: Fri, 02 Dec 2005 15:53:32 +0100
Thank u for your help. But I'm sure I use only one static DataContext. Could be that the problem ?
public class CayenneConnection {
public static DataContext dataContext;
.....
From: "Todd O'Bryan" <toddobrya..ac.com>
Reply-To: cayenne-user@objectstyle.org
To: cayenne-user@objectstyle.org
Subject: Re: object regsitered in a different DataContext
Date: Fri, 2 Dec 2005 06:32:48 -0500
Basically, persona is from a different DataContext, so CayenneConnection.dataContext is having trouble deleting it. You can useCayenneConnection.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 - 10:08:31 EST