Getting exception on querying retrieved data - database instance is not set in current thread
coolksrini opened this issue · comments
Hi All,
I am testing the spring-boot-orientdb-hello project with the below request:
@Autowired
private PersonRepository repository;
@RequestMapping("/person/list")
public List<Person> personList() throws JsonProcessingException {
log.debug("Got request for person list");
List<Person> persons = repository.findAll();
for (Person person : persons) {
log.debug("First Name: " + person.getFirstName());
log.debug("Last Name: " + person.getLastName());
}
//ObjectMapper mapper = new ObjectMapper();
//String jsonString = mapper.writeValueAsString(botRecords);
//return jsonString;
return persons;
}
com.orientechnologies.orient.core.exception.ODatabaseException: The database instance is not set in the current thread. Be sure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db);
at com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal.get(ODatabaseRecordThreadLocal.java:51) ~[orientdb-core-2.2.10.jar:2.2.10]
at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.getCurrentSerializedSchema(OObjectEntitySerializer.java:113) ~[orientdb-object-2.2.10.jar:2.2.10]
at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.isIdField(OObjectEntitySerializer.java:864) ~[orientdb-object-2.2.10.jar:2.2.10]
at com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler.manageGetMethod(OObjectProxyMethodHandler.java:295) ~[orientdb-object-2.2.10.jar:2.2.10]
at com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler.invoke(OObjectProxyMethodHandler.java:114) ~[orientdb-object-2.2.10.jar:2.2.10]
at org.springframework.boot.orientdb.hello.data.Person_$$javassist_0.getFirstName(Person$$_javassist_0.java) ~[classes/:na]
at org.springframework.boot.orientdb.hello.rest.PersonController.personList(PersonController.java:30) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
@coolksrini can you please clarify which version of OrientDB you are using? Also, what branch of Orient Spring Data are you trying? OSD uses ThreadLocal to cache connections. My guess is that your code is forking another thread somehow. I have used OSD successfully with SpringBoot.
@RAndrews137 I was using OrientDB 2.2.17 and I had tried with 0.13 release branch of Orient Spring Data.
@coolksrini I would suggest using the 2.2.x OSD which is currently 0.14-SNAPSHOT I believe. I would suggest taking a look at your threads. As mentioned earlier, OSD uses ThreadLocal to cache db connections.
on branch develop I added the same repository and all works fine.
I've updated versions of orient, spring-boot and data on develop and 2.2.x branch, I hipe this could improve stability as well