org.hibernate.service.UnknownServiceException: Unknown service requested

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.


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.