我的项目处于起步阶段,我在休眠时遇到了一个大问题。我正在使用带有 c3p0 0.9.1.2 的休眠 4.1.8-Final。
我有以下实体类:
@javax.persistence.Entity
@Table(name = "CUSTOMER")
public class Customer extends Entity {
@Transient
private static final long serialVersionUID = 3326144323537452197L;
private String customerId;
private String customerName;
private boolean active;
public Customer() {
super();
}
@NaturalId
@Column(name = "CUSTOMER_ID", nullable = false)
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
@Lob
@Column(name = "CUSTOMER_NAME", nullable = false)
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
@Column(name = "ACTIVE", nullable = false)
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
}
如您所见,customerName
已设置为Lob
. 现在第一次保存操作给了我以下错误:
2012-12-15 01:37:25,670 ERROR [com.edfx.adb.web.controller.AdminController] java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setCharacterStream(ILjava/io/Reader;J)V
2012-12-15 01:37:25,670 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2012-12-15 01:37:25,670 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
2012-12-15 01:37:25,670 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2012-12-15 01:37:25,670 ERROR [com.edfx.adb.web.controller.AdminController] at java.lang.reflect.Method.invoke(Method.java:601)
2012-12-15 01:37:25,670 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
2012-12-15 01:37:25,670 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
2012-12-15 01:37:25,670 ERROR [com.edfx.adb.web.controller.AdminController] at $Proxy240.setCharacterStream(Unknown Source)
2012-12-15 01:37:25,670 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$3$1.doBind(ClobTypeDescriptor.java:83)
2012-12-15 01:37:25,685 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92)
2012-12-15 01:37:25,685 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280)
2012-12-15 01:37:25,685 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275)
2012-12-15 01:37:25,701 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57)
2012-12-15 01:37:25,701 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2747)
2012-12-15 01:37:25,701 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2722)
2012-12-15 01:37:25,701 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.persister.entity.AbstractEntityPersister$4.bindValues(AbstractEntityPersister.java:2929)
2012-12-15 01:37:25,701 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
2012-12-15 01:37:25,716 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2936)
2012-12-15 01:37:25,716 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3447)
2012-12-15 01:37:25,716 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
2012-12-15 01:37:25,716 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
2012-12-15 01:37:25,716 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)
2012-12-15 01:37:25,732 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)
2012-12-15 01:37:25,732 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)
2012-12-15 01:37:25,732 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:320)
2012-12-15 01:37:25,732 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287)
2012-12-15 01:37:25,748 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193)
2012-12-15 01:37:25,748 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
2012-12-15 01:37:25,748 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
2012-12-15 01:37:25,748 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
2012-12-15 01:37:25,748 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
2012-12-15 01:37:25,763 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
2012-12-15 01:37:25,763 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
2012-12-15 01:37:25,763 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:756)
2012-12-15 01:37:25,763 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.internal.SessionImpl.save(SessionImpl.java:748)
2012-12-15 01:37:25,779 ERROR [com.edfx.adb.web.controller.AdminController] at org.hibernate.internal.SessionImpl.save(SessionImpl.java:744)
2012-12-15 01:37:25,779 ERROR [com.edfx.adb.web.controller.AdminController] at com.edfx.adb.dao.base.BaseDao.save(BaseDao.java:21)
2012-12-15 01:37:25,779 ERROR [com.edfx.adb.web.controller.AdminController] at com.edfx.adb.service.CustomerService.addNewCustomer(CustomerService.java:26)
2012-12-15 01:37:25,779 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2012-12-15 01:37:25,779 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
2012-12-15 01:37:25,794 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2012-12-15 01:37:25,794 ERROR [com.edfx.adb.web.controller.AdminController] at java.lang.reflect.Method.invoke(Method.java:601)
2012-12-15 01:37:25,794 ERROR [com.edfx.adb.web.controller.AdminController] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
2012-12-15 01:37:25,794 ERROR [com.edfx.adb.web.controller.AdminController] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
2012-12-15 01:37:25,794 ERROR [com.edfx.adb.web.controller.AdminController] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
2012-12-15 01:37:25,794 ERROR [com.edfx.adb.web.controller.AdminController] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
2012-12-15 01:37:25,810 ERROR [com.edfx.adb.web.controller.AdminController] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
2012-12-15 01:37:25,810 ERROR [com.edfx.adb.web.controller.AdminController] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
2012-12-15 01:37:25,810 ERROR [com.edfx.adb.web.controller.AdminController] at $Proxy236.addNewCustomer(Unknown Source)
2012-12-15 01:37:25,810 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2012-12-15 01:37:25,810 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
2012-12-15 01:37:25,826 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2012-12-15 01:37:25,826 ERROR [com.edfx.adb.web.controller.AdminController] at java.lang.reflect.Method.invoke(Method.java:601)
2012-12-15 01:37:25,826 ERROR [com.edfx.adb.web.controller.AdminController] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
2012-12-15 01:37:25,841 ERROR [com.edfx.adb.web.controller.AdminController] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
2012-12-15 01:37:25,841 ERROR [com.edfx.adb.web.controller.AdminController] at $Proxy237.addNewCustomer(Unknown Source)
2012-12-15 01:37:25,841 ERROR [com.edfx.adb.web.controller.AdminController] at com.edfx.adb.web.controller.AdminController.saveCustomer(AdminController.java:25)
2012-12-15 01:37:25,841 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2012-12-15 01:37:25,841 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
2012-12-15 01:37:25,841 ERROR [com.edfx.adb.web.controller.AdminController] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2012-12-15 01:37:25,857 ERROR [com.edfx.adb.web.controller.AdminController] at java.lang.reflect.Method.invoke(Method.java:601)
2012-12-15 01:37:25,857 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
2012-12-15 01:37:25,857 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
2012-12-15 01:37:25,857 ERROR [com.edfx.adb.web.controller.AdminController] at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
2012-12-15 01:37:25,857 ERROR [com.edfx.adb.web.controller.AdminController] at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148)
2012-12-15 01:37:25,872 ERROR [com.edfx.adb.web.controller.AdminController] at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
2012-12-15 01:37:25,872 ERROR [com.edfx.adb.web.controller.AdminController] at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
2012-12-15 01:37:25,872 ERROR [com.edfx.adb.web.controller.AdminController] at javax.faces.component.UICommand.broadcast(UICommand.java:300)
2012-12-15 01:37:25,872 ERROR [com.edfx.adb.web.controller.AdminController] at javax.faces.component.UIData.broadcast(UIData.java:1093)
2012-12-15 01:37:25,872 ERROR [com.edfx.adb.web.controller.AdminController] at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
2012-12-15 01:37:25,888 ERROR [com.edfx.adb.web.controller.AdminController] at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
2012-12-15 01:37:25,888 ERROR [com.edfx.adb.web.controller.AdminController] at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
2012-12-15 01:37:25,888 ERROR [com.edfx.adb.web.controller.AdminController] at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
2012-12-15 01:37:25,904 ERROR [com.edfx.adb.web.controller.AdminController] at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
2012-12-15 01:37:25,904 ERROR [com.edfx.adb.web.controller.AdminController] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
2012-12-15 01:37:25,904 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
2012-12-15 01:37:25,904 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
2012-12-15 01:37:25,904 ERROR [com.edfx.adb.web.controller.AdminController] at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119)
2012-12-15 01:37:25,919 ERROR [com.edfx.adb.web.controller.AdminController] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
2012-12-15 01:37:25,919 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
2012-12-15 01:37:25,919 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
2012-12-15 01:37:25,919 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
2012-12-15 01:37:25,935 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
2012-12-15 01:37:25,935 ERROR [com.edfx.adb.web.controller.AdminController] at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
2012-12-15 01:37:25,935 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
2012-12-15 01:37:25,935 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
2012-12-15 01:37:25,935 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
2012-12-15 01:37:25,950 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
2012-12-15 01:37:25,950 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
2012-12-15 01:37:25,950 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
2012-12-15 01:37:25,950 ERROR [com.edfx.adb.web.controller.AdminController] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
2012-12-15 01:37:25,950 ERROR [com.edfx.adb.web.controller.AdminController] at java.lang.Thread.run(Thread.java:722)
简而言之,错误消息是:
java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setCharacterStream(ILjava/io/Reader;J)V
通过谷歌搜索这个错误,我发现第一个链接说降级到休眠 4.1.3-Final 可以解决这个问题。这奏效了。但我的目标是使用最新版本的休眠。我读到hibernate没有太多的连接池。导致何时需要连接池;它将从服务器获取该池。
我的问题是,在 JBoss AS 7 中运行的生产环境中,是否有必要使用第三方 c3p0;如果没有,我可以删除 c3p0;或者有这个问题的解决方案?