Hibernate returns stale data from the cache instead of the latest record from the DB

In my application, I noticed a Hibernate cache issue. The service response shows a record which was previously deleted while, in the database, the record status is shown as deleted.

It’s not clear what you are asking. Try to provide more details.

i am using basic configuration properties for hibernate.
configuration.setProperty(“hibernate.connection.url”, “jdbc:mysql://” + URL);
configuration.setProperty(“hibernate.dialect”, “org.hibernate.dialect.MySQLDialect”);
configuration.setProperty(“hibernate.connection.username”, USER_NAME);
configuration.setProperty(“hibernate.connection.password”, PASSWORD);
configuration.setProperty(“hibernate.connection.driver_class”, “com.mysql.jdbc.Driver”);
configuration.setProperty(“hibernate.current_session_context_class”, “thread”);
configuration.setProperty(“hibernate.hbm2ddl.auto”, “update”);
configuration.setProperty(“hibernate.cglib.use_reflection_optimizer”, “true”);
configuration.setProperty(“hibernate.cache.provider_class”, “org.hibernate.cache.NoCacheProvider”);
configuration.setProperty(“hibernate.connection.CharSet”, “utf8”);
configuration.setProperty(“hibernate.connection.characterEncoding”, “utf8”);
configuration.setProperty(“hibernate.connection.useUnicode”, “true”);
configuration.setProperty(“hibernate.autoReconnect”, “true”);
and closing the session also but also getting the data which is showing the status as non active in db but coming as active .

Maybe a different transaction has modified the data, but the current Session already cached the old data. Or, since you are using MySQL, the default isolation level is REPEATABLE_READ, meaning that even if a concurrent transaction modifies a record, you still see the record as it was at the beginning of your transactions. For more details check out these two articles:

Yes i’m using mysql .but not got too much can u please elaborate more.

If you read those article, you are going to understand. Take your time to explore the MySQL documentation in depth, as well as the Hibernate User Guide. After you finish reading all those, you are going to find more than the answer to this question.

2018-10-30 14:19:50,582 | WARN  | qtp584452319-69  | PojoEntityTuplizer               | 459 - com.bdbizviz.forms - 1.0.0 | HHH000305: Could not create proxy factory for:com.bdbizviz.forms.entities.FormEmail
org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: com.bdbizviz.forms.entities.FormEmail
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxyFactory(JavassistLazyInitializer.java:166)
	at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.postInstantiate(JavassistProxyFactory.java:67)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:224)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:212)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:80)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)[:1.8.0_151]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)[:1.8.0_151]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)[:1.8.0_151]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)[:1.8.0_151]
	at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
	at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:403)
	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520)
	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)[:1.8.0_151]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)[:1.8.0_151]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)[:1.8.0_151]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)[:1.8.0_151]
	at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
	at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
	at com.bdbizviz.forms.util.BizvizHibernateUtil.buildSessionFactory(BizvizHibernateUtil.java:66)
	at com.bdbizviz.forms.util.BizvizHibernateUtil.<clinit>(BizvizHibernateUtil.java:36)
	at com.bdbizviz.forms.util.BizvizHibernateTemplate.getOpenSession(BizvizHibernateTemplate.java:558)
	at com.bdbizviz.forms.util.BizvizHibernateTemplate.openSession(BizvizHibernateTemplate.java:533)
	at com.bdbizviz.forms.dao.FormsDaoHibernate.getAllFrequencyInterval(FormsDaoHibernate.java:53)
	at com.bdbizviz.forms.manager.FormsManager.getAllFrequencyInterval(FormsManager.java:82)
	at com.bdbizviz.forms.impl.FormsImpl.getAllFrequencyInterval(FormsImpl.java:906)
	at com.bdbizviz.forms.impl.FormsImpl.pluginService(FormsImpl.java:56)
	at com.bdbizviz.rs.services.impl.BizVizPluginServiceImpl.bizvizPluginServiceRouter(BizVizPluginServiceImpl.java:113)[425:com.bdbizviz.rs.services:3.6.0]
	at sun.reflect.GeneratedMethodAccessor81.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_151]
	at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_151]
	at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:188)[94:org.apache.cxf.cxf-api:2.7.11]
	at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:104)[94:org.apache.cxf.cxf-api:2.7.11]
	at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204)[127:org.apache.cxf.cxf-rt-frontend-jaxrs:2.7.11]
	at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101)[127:org.apache.cxf.cxf-rt-frontend-jaxrs:2.7.11]
	at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)[94:org.apache.cxf.cxf-api:2.7.11]
	at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)[94:org.apache.cxf.cxf-api:2.7.11]
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)[94:org.apache.cxf.cxf-api:2.7.11]
	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)[94:org.apache.cxf.cxf-api:2.7.11]
	at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:241)[121:org.apache.cxf.cxf-rt-transports-http:2.7.11]
	at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248)[121:org.apache.cxf.cxf-rt-transports-http:2.7.11]
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222)[121:org.apache.cxf.cxf-rt-transports-http:2.7.11]
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153)[121:org.apache.cxf.cxf-rt-transports-http:2.7.11]
	at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)[121:org.apache.cxf.cxf-rt-transports-http:2.7.11]
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)[121:org.apache.cxf.cxf-rt-transports-http:2.7.11]
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:206)[121:org.apache.cxf.cxf-rt-transports-http:2.7.11]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)[102:org.apache.geronimo.specs.geronimo-servlet_3.0_spec:1.0.0]
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262)[121:org.apache.cxf.cxf-rt-transports-http:2.7.11]
	at Proxyf0997fc0_c384_4c6b_bdf8_2ddc4d0fe844.service(Unknown Source)[:]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:69)[116:org.ops4j.pax.web.pax-web-jetty:3.2.9]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:240)[116:org.ops4j.pax.web.pax-web-jetty:3.2.9]
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:427)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:75)[116:org.ops4j.pax.web.pax-web-jetty:3.2.9]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.server.Server.handle(Server.java:370)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:984)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1045)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:861)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:236)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[107:org.eclipse.jetty.aggregate.jetty-all-server:8.1.19.v20160209]
	at java.lang.Thread.run(Thread.java:748)[:1.8.0_151]
Caused by: java.lang.NoClassDefFoundError: javassist/CannotCompileException
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxyFactory(JavassistLazyInitializer.java:158)
	... 77 more
Caused by: java.lang.ClassNotFoundException: javassist.CannotCompileException not found by com.bdbizviz.forms [459]
	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
	at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_151]
	... 78 more

My server is getting down i’m not bale to resolve it till now.i have used many thing but not working.Can you please help me what changes i need to do so that i can resolved it.???
please respond asap

Looks like an OSGI class loading issue. You need to check your dependencies as you either miss the javassist dependency or you are using an incompatible version which is not what Hibernate expects.

I’m going to close this thread since it looks like you are using it post whatever issue you have with Hibernate even if it’s not relevant to your original post or the thread title.

So, there are 3 things you need to do:

  1. Use a separate post whenever you have some issue.
  2. Try to be as descriptive as possible, otherwise no one will figure out what causes your problem, and you won’t get any solution.
  3. Last, but not least, you need to read the entire User Guide. That’s the best way to know how to use Hibernate.