Seems that you're looking just for a name of DB table, to clean it before
insert? If so, why cannot you use
context.getEntityResolver().getObjEntity(String) method? I don't see why you
need that dummyContext in that case
2008/7/23, Borut Bolina <borut.bolcina@gmail.com>:
>
> 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 - 05:13:20 EDT