Hello,
is there a better solution to creating a dummyDataContext just to get
dbEntityName and then unregistering all objects:
DataContext context = DataContext.createDataContext();
// item is TRANSIENT
CayenneDataObject item = (CayenneDataObject)
allItemsFromOneProvider.iterator().next();
// so create a dummy data context
DataContext dummyContext = DataContext.createDataContext();
dummyContext.registerNewObject(item);
// just to find out table name
logger.debug("item.getObjEntity().getDbEntityName(): " +
item.getObjEntity().getDbEntityName());
String tableName = item.getObjEntity().getDbEntityName();
// now unregister item
dummyContext.unregisterObjects(allItemsFromOneProvider);
context.performGenericQuery(new NamedQuery("DeleteAll",
Collections.singletonMap("table", tableName)));
// now do a clean insert
logger.info("Persisting...");
for (Iterator i = allItemsFromOneProvider.iterator();
i.hasNext();) {
item = (CayenneDataObject) i.next();
context.registerNewObject(item);
}
context.commitChanges();
Regards,
Borut
This archive was generated by hypermail 2.0.0 : Wed Jul 23 2008 - 04:45:50 EDT