我正在使用Apache Derby DB的hibernate。当我第一次运行我的应用程序时,它会在session.save(对象)暂停,而不是继续进行,但是当我第二次构建我的应用程序时,它会在下面抛出错误。
StackTrace如下: -
10:05:42,131 ERROR [stderr] (default task-2) org.hibernate.exception.LockAcquisitionException: could not extract ResultSet
10:05:42,131 ERROR [stderr] (default task-2) at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:92)
10:05:42,131 ERROR [stderr] (default task-2) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
10:05:42,131 ERROR [stderr] (default task-2) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
10:05:42,131 ERROR [stderr] (default task-2) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
10:05:42,132 ERROR [stderr] (default task-2) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91)
10:05:42,132 ERROR [stderr] (default task-2) at org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:122)
10:05:42,132 ERROR [stderr] (default task-2) at org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:73)
10:05:42,132 ERROR [stderr] (default task-2) at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
10:05:42,132 ERROR [stderr] (default task-2) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
10:05:42,132 ERROR [stderr] (default task-2) at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
10:05:42,132 ERROR [stderr] (default task-2) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
10:05:42,132 ERROR [stderr] (default task-2) at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
10:05:42,132 ERROR [stderr] (default task-2) at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
10:05:42,133 ERROR [stderr] (default task-2) at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
10:05:42,133 ERROR [stderr] (default task-2) at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
10:05:42,133 ERROR [stderr] (default task-2) at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
10:05:42,133 ERROR [stderr] (default task-2) at rest.food.ordering.dao.FoodOrderingDaoImpl.saveServingLocation(FoodOrderingDaoImpl.java:31)
10:05:42,133 ERROR [stderr] (default task-2) at rest.food.ordering.service.FoodOrderingServiceImpl.saveServingLocations(FoodOrderingServiceImpl.java:30)
10:05:42,133 ERROR [stderr] (default task-2) at rest.food.ordering.controller.FoodOrderingController.saveServingLocations(FoodOrderingController.java:26)
10:05:42,133 ERROR [stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:05:42,133 ERROR [stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
10:05:42,133 ERROR [stderr] (default task-2) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
10:05:42,134 ERROR [stderr] (default task-2) at java.lang.reflect.Method.invoke(Method.java:498)
10:05:42,134 ERROR [stderr] (default task-2) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
10:05:42,134 ERROR [stderr] (default task-2) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
10:05:42,134 ERROR [stderr] (default task-2) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
10:05:42,134 ERROR [stderr] (default task-2) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
10:05:42,135 ERROR [stderr] (default task-2) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
10:05:42,135 ERROR [stderr] (default task-2) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
10:05:42,135 ERROR [stderr] (default task-2) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
10:05:42,135 ERROR [stderr] (default task-2) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
10:05:42,135 ERROR [stderr] (default task-2) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
10:05:42,136 ERROR [stderr] (default task-2) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
10:05:42,136 ERROR [stderr] (default task-2) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
10:05:42,136 ERROR [stderr] (default task-2) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
10:05:42,136 ERROR [stderr] (default task-2) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
10:05:42,136 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
10:05:42,136 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
10:05:42,136 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
10:05:42,137 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
10:05:42,137 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:05:42,137 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
10:05:42,137 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
10:05:42,137 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:05:42,137 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
10:05:42,137 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
10:05:42,137 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
10:05:42,138 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
10:05:42,138 ERROR [stderr] (default task-2) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
10:05:42,138 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
10:05:42,138 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:05:42,138 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
10:05:42,139 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:05:42,139 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:05:42,139 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:285)
10:05:42,139 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:264)
10:05:42,139 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
10:05:42,139 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:175)
10:05:42,140 ERROR [stderr] (default task-2) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
10:05:42,140 ERROR [stderr] (default task-2) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:792)
10:05:42,140 ERROR [stderr] (default task-2) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
10:05:42,140 ERROR [stderr] (default task-2) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
10:05:42,140 ERROR [stderr] (default task-2) at java.lang.Thread.run(Thread.java:745)
10:05:42,140 ERROR [stderr] (default task-2) Caused by: java.sql.SQLTransactionRollbackException: Too much contention on sequence SERVING_LOCATION_SEQUENCE. This is probably caused by an uncommitted scan of the SYS.SYSSEQUENCES catalog. Do not query this catalog directly. Instead, use the SYSCS_UTIL.SYSCS_PEEK_AT_SEQUENCE function to view the current value of a sequence generator.
10:05:42,141 ERROR [stderr] (default task-2) at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
10:05:42,141 ERROR [stderr] (default task-2) at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
10:05:42,141 ERROR [stderr] (default task-2) at org.apache.derby.client.am.ClientPreparedStatement.executeQuery(Unknown Source)
10:05:42,141 ERROR [stderr] (default task-2) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
10:05:42,141 ERROR [stderr] (default task-2) ... 58 more
10:05:42,142 ERROR [stderr] (default task-2) Caused by: ERROR X0Y84: Too much contention on sequence SERVING_LOCATION_SEQUENCE. This is probably caused by an uncommitted scan of the SYS.SYSSEQUENCES catalog. Do not query this catalog directly. Instead, use the SYSCS_UTIL.SYSCS_PEEK_AT_SEQUENCE function to view the current value of a sequence generator.
10:05:42,142 ERROR [stderr] (default task-2) at org.apache.derby.client.am.ClientStatement.completeSqlca(Unknown Source)
10:05:42,142 ERROR [stderr] (default task-2) at org.apache.derby.client.net.NetStatementReply.parseOpenQueryError(Unknown Source)
10:05:42,142 ERROR [stderr] (default task-2) at org.apache.derby.client.net.NetStatementReply.parseOPNQRYreply(Unknown Source)
10:05:42,142 ERROR [stderr] (default task-2) at org.apache.derby.client.net.NetStatementReply.readOpenQuery(Unknown Source)
10:05:42,142 ERROR [stderr] (default task-2) at org.apache.derby.client.net.StatementReply.readOpenQuery(Unknown Source)
10:05:42,142 ERROR [stderr] (default task-2) at org.apache.derby.client.net.NetStatement.readOpenQuery_(Unknown Source)
10:05:42,143 ERROR [stderr] (default task-2) at org.apache.derby.client.am.ClientStatement.readOpenQuery(Unknown Source)
10:05:42,143 ERROR [stderr] (default task-2) at org.apache.derby.client.am.ClientPreparedStatement.flowExecute(Unknown Source)
10:05:42,143 ERROR [stderr] (default task-2) at org.apache.derby.client.am.ClientPreparedStatement.executeQueryX(Unknown Source)
10:05:42,143 ERROR [stderr] (default task-2) ... 60 more
实体类如下: -
package rest.food.ordering.dbo;
import java.math.BigInteger;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@Entity
@Table(name="SERVING_LOCATION")
public class ServingLocationDBO {
@Id
@GeneratedValue(generator = "SER_LOC_SEQ", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "SER_LOC_SEQ", sequenceName = "SERVING_LOCATION_SEQUENCE",initialValue=1, allocationSize=1)
@Column(name="LOCATION_ID",nullable = false)
private BigInteger locationId;
@Column(name="LOCATION_NAME",nullable = false, length = 100)
private String locationName;
public BigInteger getLocationId() {
return locationId;
}
public void setLocationId(BigInteger locationId) {
this.locationId = locationId;
}
public String getLocationName() {
return locationName;
}
public void setLocationName(String locationName) {
this.locationName = locationName;
}
}
我是否需要手动创建序列到数据库中,因为它可以通过手动创建的序列正常工作?
请帮我解决这个问题。
答案 0 :(得分:-1)
嗯,而不是GenerateType.SEQUENCE尝试GenerateType.AUTO。我认为序列在休眠后被弃用4.让我知道它是否有用。