org.hibernate.service.UnknownServiceException: Unknown service requested

≡放荡痞女 提交于 2019-12-05 07:42:57

I might be totally off here, but to me this seems to be a session handling exception. In @Before you open and close session, then in save() you get the current session, which is maybe the one you just closed, leading to an exception. Try if it works if you don't close it in @Before (I know it's not the solution, just to test the theory). You can also try opening a new session in repository instead of getting the current one (also not the solution). The only difference I see compared with our working test setup is that in @Before we also call our repository methods, marked as @Transactional, instead of creating a session directly.

I ran into a similar error except the unknown service was [org.hibernate.cache.spi.RegionFactory] which only occurred when the spring context was started a second time. The problem was due to a partially destroyed beanFactory and transaction manager cache in org.springframework.transaction.interceptor.TransactionAspectSupport. The solution was to call org.springframework.transaction.interceptor.TransactionAspectSupport#clearTransactionManagerCache.

Steve Single

I ran into this same error. I discovered the cause in my case. My experience may help someone else.

I was calling ServiceRegistryBuilder.destroy() in my sessionFactoryCreatedmethod rather than my sessionFactoryClosed method.

Basically, I destroyed my service registry then tried to get a new session, and this makes Hibernate produce the misleading error message.

Therefore, I suggest if people get this error, check they are not closing their session or registry and then trying to get it again.

For any future Google searchers:

When I saw this problem it was caused by an error in the sql script that was being run before the tests started. Scrolling back far enough through the logs revealed the error, so it's worth looking back to check that an UnknownServiceException isn't just a side effect of another problem.

Its Nothing , its cache problem . just close your server and clean your tomcat . then restart . I solved it like this.

I found out this error during Hibernate unit test creating. I created session by my util class: Session session = XmlSessionUtil.getSessionFactory().openSession(); In one test was session closed by session.close(); When I removed statement closing session all tests passed. So in my case was exception reason closed session.

I got this error during working with hibernate framework. So getting rid off from this error I change the sequence of closing session and session factory. like this.

session.close();
sessionFactory.close();

It worked for me. Hope it will work for you.

I'm adding onto another answer here from Ramanpreet Singh. I experienced this issue when I used kill -9 on tomcat. I can reliably re-create the problem this way. I have to start up my server, gracefully close it, then start it up again to clear up the problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!