[Hibernate-JIRA] Created: (HHH-7233) setMaxResults or getSingleResult, combined with pessimistic locking, fails on Oracle with ORA-02014
by Scott Van Wart (JIRA)
setMaxResults or getSingleResult, combined with pessimistic locking, fails on Oracle with ORA-02014
---------------------------------------------------------------------------------------------------
Key: HHH-7233
URL: https://hibernate.onjira.com/browse/HHH-7233
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 4.1.2
Environment: Hibernate 4.1.2, Oracle 11gR2
Reporter: Scott Van Wart
I have a DAO method that does the following:
return this.createNamedQuery( "systemTasks(machineId,status,maxExecuteTimestamp)" )
.setParameter( "machineId", machineId )
.setParameter( "status", status )
.setParameter( "maxExecuteTimestamp", maxExecuteTimestamp )
.setLockMode( LockModeType.PESSIMISTIC_WRITE )
.setMaxResults( 1 )
.getSingleResult();
HQL is:
select st from SystemTask st
where st.machineId = :machineId and st.status = :status
and st.executeTimestamp <= :maxExecuteTimestamp
order by st.executeTimestamp
Hibernate generates the following SQL:
select * from (
select [column list]
from jaseadm.system_task systemtask0_
where systemtask0_.machine_id=?
and systemtask0_.task_status_id=?
and systemtask0_.execute_timestamp<=?
order by systemtask0_.execute_timestamp )
where rownum <= ? for update
Which fails with:
ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
This means that:
- setLockMode (pessimistic) can't be used with setMaxResults when there's an order specified, because the oracle dialect only accommodates the "for update" clause and doesn't do anything with an "order by" clause.
- setLockMode (pessimistic) can't be used with getSingleResult when there's an order by specified, because Hibernate indiscriminately calls setMaxResults in org.hibernate.ejb.getSingleResult():
boolean mucked = false;
// IMPL NOTE : the mucking with max results here is attempting to help the user from shooting themselves
// in the foot in the case where they have a large query by limiting the query results to 2 max
// SQLQuery cannot be safely paginated, leaving the user's choice here.
if ( getSpecifiedMaxResults() != 1 &&
! ( SQLQuery.class.isAssignableFrom( query.getClass() ) ) ) {
mucked = true;
query.setMaxResults( 2 ); //avoid OOME if the list is huge
}
List<X> result = query.list();
if ( mucked ) {
query.setMaxResults( getSpecifiedMaxResults() );
}
Honestly I would prefer the OOM prevention stuff be removed, or configurable through the session factory, as I end up with a lot of natural key queries that look like:
select * from ( ... ) where rownum <= 1
When I haven't called setMaxResults myself.
Related to HHH-3298 and HHH-1168 (7 years unresolved). Note that unlike HH-1168, this breaks getSingleResult as well due to the whole "mucked" code.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years
[Hibernate-JIRA] Created: (HHH-5971) Bad performance UpdateTimestampsCache ReentrantReadWriteLock
by Fernando Paris (JIRA)
Bad performance UpdateTimestampsCache ReentrantReadWriteLock
------------------------------------------------------------
Key: HHH-5971
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5971
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.1
Environment: hibernate 3.6.1, jboss as eap 4.3
Reporter: Fernando Paris
Priority: Critical
Performance bootleneck created by UpdateTimestampsCache invalidate, generating full heap. On the threaddump have 346 threads waiting for
"ajp-0.0.0.0-5490-251" daemon prio=10 tid=0x00002aabc683c000 nid=0x7673 waiting on condition [0x000000005b4da000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00002aaac1c8c9d0> (a java.util.concurrent.locks.ReentrantReadWriteLock$NonfairSync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:747)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:778)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1114)
at java.util.concurrent.locks.ReentrantReadWriteLock$WriteLock.lock(ReentrantReadWriteLock.java:807)
at org.hibernate.cache.UpdateTimestampsCache.invalidate(UpdateTimestampsCache.java:88)
at org.hibernate.engine.ActionQueue$AfterTransactionCompletionProcessQueue.afterTransactionCompletion(ActionQueue.java:604)
at org.hibernate.engine.ActionQueue.afterTransactionCompletion(ActionQueue.java:209)
at org.hibernate.impl.SessionImpl.afterTransactionCompletion(SessionImpl.java:602)
at org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:292)
at org.hibernate.impl.SessionImpl.afterOperation(SessionImpl.java:595)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1273)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.springframework.orm.hibernate3.HibernateTemplate$34.doInHibernate(HibernateTemplate.java:1024)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQueryAndNamedParam(HibernateTemplate.java:1015)
at com.rumbo.hotel.dbaccess.dao.impl.DhotMetadataDAOImpl.getByDescriptionKey(DhotMetadataDAOImpl.java:46)
at com.rumbo.alojamientos.tools.parameter.HotelParameterCacheManager.getParameter(HotelParameterCacheManager.java:113)
at com.rumbo.alojamientos.tools.parameter.HotelParameterCacheManager.getParameterValue(HotelParameterCacheManager.java:76)
at com.rumbo.alojamientos.tools.parameter.HotelParameterCacheManager.getParameterValue(HotelParameterCacheManager.java:87)
at com.rumbo.alojamientos.tools.logging.LoggingUtilities.isLogWritingActive(LoggingUtilities.java:189)
at com.rumbo.alojamientos.tools.logging.LoggingUtilities.isLogWritingActive(LoggingUtilities.java:232)
at com.rumbo.alojamientos.tools.logging.LoggingUtilities.saveLog(LoggingUtilities.java:141)
at com.rumbo.hoteles.ws.interceptor.LoggingInterceptor.saveLog(LoggingInterceptor.java:168)
at com.rumbo.hoteles.ws.interceptor.LoggingInterceptor.handleRequest(LoggingInterceptor.java:94)
at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:213)
at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:168)
at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:88)
at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:57)
at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:230)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.rumbo.mvc.encoding.EncodingFilter.doFilter(EncodingFilter.java:61)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:543)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:437)
at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:381)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years