Hi unfortunately in current implementation you cannot reuse OSQLSynchQuery objects.
Just take a look a this https://github.com/orientechnologies/orientdb/issues/2923 regards Luigi 2014-10-05 14:40 GMT+02:00 rapidtransit440 <rapidtransit...@gmail.com>: > I'm trying to construct a DAO to update a front facing OrientDB database > backed by a RDBMs, my requests are made during a Quartz schedule run > anyways the relevant code > > @Component("blOrientDao") > public class OrientDAOImpl { > > @Resource(name = "blcOrientDb") > protected OrientDBServer orientDBServer; > > protected OSQLSynchQuery<OCategory> categoryById = > getById(OCategoryImpl.class); > ..... > public OCategory findCategoryById(Long id){ > List<OCategory> query = > orientDBServer.getDatabase().command(categoryById).execute(id); > return query.isEmpty() ? null : query.get(0); > } > .... > protected <T> OSQLSynchQuery<T> getById(Class<?> clazz){ > return new OSQLSynchQuery<T>("SELECT * FROM " + > clazz.getSimpleName() + " WHERE id = ?"); > } > > Finding it by Id works here: > protected void indexCategories() { > List<Category> categoryDirty = > orientChangeDetectionDao.findCategoryDirty(); > if(categoryDirty != null && !categoryDirty.isEmpty()) { > for (Category category : categoryDirty) { > OCategory oCategory = > orientDAO.findCategoryById(category.getId()); > if (oCategory == null) { > oCategory = new OCategoryImpl(); > } > > orientDBServer.getDatabase().begin(OTransaction.TXTYPE.OPTIMISTIC); > oCategory.setId(category.getId()); > oCategory.setName(category.getName()); > oCategory.setUrl(category.getUrl()); > oCategory.setDescription(category.getDescription()); > > oCategory.setLongDescription(category.getLongDescription()); > orientDBServer.getDatabase().save(oCategory); > orientDBServer.getDatabase().commit(); > } > } > } > > > Then the next part is to update available facets (I don't reuse the same > category object because these are independent of each other), but when I > try to re-find the same category it's null, at first I thought maybe I > wasn't getting an instance from my current thread, but it does find > everything else > protected void indexCategoryFacets(){ > List<CategorySearchFacet> categorySearchFacetDirty = > orientChangeDetectionDao.findCategorySearchFacetDirty(); > if(categorySearchFacetDirty != null && > !categorySearchFacetDirty.isEmpty()) { > for(CategorySearchFacet catsf : categorySearchFacetDirty){ > Category category = > categoryDao.readCategoryById(catsf.getCategory().getId()); > OCategory oCategory = > orientDAO.findCategoryById(catsf.getCategory().getId()); > if(oCategory != null) { > Iterator<OFacetField> fieldIterator = > oCategory.getFacetFields().iterator(); > while(fieldIterator.hasNext()) { > OFacetField oFacetField = fieldIterator.next(); > boolean contains = false; > for (CategorySearchFacet categorySearchFacet : > category.getSearchFacets()) { > > if(categorySearchFacet.getSearchFacet().getId().equals(oFacetField.getId())) > { > contains = true; > } > } > if(!contains) { > fieldIterator.remove(); > } > } > OFacetField facetField = > orientDAO.findFacetFieldById(catsf.getSearchFacet().getId()); > if (facetField != null && > !oCategory.getFacetFields().contains(facetField)) { > > orientDBServer.getDatabase().begin(OTransaction.TXTYPE.OPTIMISTIC); > oCategory.getFacetFields().add(facetField); > orientDBServer.getDatabase().save(oCategory); > orientDBServer.getDatabase().commit(); > } > } > } > } > } > > > -- > > --- > You received this message because you are subscribed to the Google Groups > "OrientDB" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to orient-database+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Luigi Dell'Aquila Orient Technologies LTD -- --- You received this message because you are subscribed to the Google Groups "OrientDB" group. To unsubscribe from this group and stop receiving emails from it, send an email to orient-database+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.