编程语言
首页 > 编程语言> > java – JBoss AS 7中的hibernate需要c3p0连接池

java – JBoss AS 7中的hibernate需要c3p0连接池

作者:互联网

我的项目还处于起步阶段,我对hibernate存在很大的问题.我正在使用hibernate 4.1.8-Final和c3p0 0.9.1.2.

我有以下实体类:

@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

通过谷歌搜索这个错误,我发现第一个link说降级到休眠4.1.3-Final可以解决问题.这很有效.但我的目标是使用最新版本的hibernate.我读到hibernate没有太多的连接池;当它需要连接池时;它将从服务器获取该池.

我的问题是,在JBoss AS 7中运行的生产环境中,是否有必要使用第三方c3p0;如果不是我可以删除c3p0;或者有这个问题的解决方案?

解决方法:

请更新到c3p0-0.9.2-pre7.它已经成熟 – 除非出现意外情况,下一个版本将是c3p0-0.9.2 final. hibernate最近添加了一些JDBC4依赖项. c3p0还没有完整的JDBC4支持(它会在0.9.2最终确定之后),但是c3p0-0.9.2-pre7支持这些方法来维护hibernate依赖.

0.9.2-pre7是0.9.1.2的替代品.只需删除c3p0-0.9.1.2.jar并替换为BOTH c3p0-0.9.2-pre7.jar和mchange-commons-java-0.2.3.2.jar.或者只使用Maven central [groupId:com.mchange,artifactId:c3p0,version:0.9.2-pre7],让传递依赖关注其余部分.请参阅文档的最顶部,http://www.mchange.com/projects/c3p0/以获取下载信息等.

hibernate不需要c3p0.您可以使用其他连接池.但是虽然我有偏见,但我认为c3p0是一个不错的选择! (我是c3p0的作者.)

标签:java,hibernate,jboss7-x,c3p0
来源: https://codeday.me/bug/20190712/1444160.html