- 浏览: 82175 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
h_time:
good
Liferay Portal 6学习笔记2:Liferay Portal6安装及简单设置 -
fileEye:
good job!
Liferay Portal 6学习笔记2:Liferay Portal6安装及简单设置 -
ko8e:
分享了,谢谢
Liferay Portal 6学习笔记2:Liferay Portal6安装及简单设置 -
cracet:
原来如此,我都快崩溃啦,感谢有你!
spring+hibernate annotation 在JBoss下的错误处理 -
haoruiqian:
很好,学习了。
Liferay Portal 6学习笔记2:Liferay Portal6安装及简单设置
spring+hibernate的工程从tomcat5.5移植到JBoss4.2.2。
spring 2.5.4
hibernate 3.2
在tomcat下均正常。但是在JBoss下执行如下查询的时候出现错误:
private final static SessionFactory sessionFactory; private static final ThreadLocal threadSession = new ThreadLocal(); private static final ThreadLocal threadTransaction = new ThreadLocal(); public static void beginTransaction() throws DaoException { Transaction tx = (Transaction) threadTransaction.get(); try { if (tx == null) { tx = getSession(true).beginTransaction(); threadTransaction.set(tx); } } catch (HibernateException ex) { log.error("Fail to begin transaction", ex); throw new DaoException("Fail to begin transaction", ex); } } public static Session getSession(boolean openSession) throws DaoException { Session s = (Session) threadSession.get(); //if (openSession) { //2008-12-17 if ((openSession)&&(s==null)) { try { if (s == null) { s = sessionFactory.openSession(); threadSession.set(s); } } catch (HibernateException ex) { log.error("Fail to open session", ex); throw new DaoException("Fail to open session", ex); } } return s; } public List findByCriterions(Class clazz, List restrictions) throws DaoException { List objs = new ArrayList(); try { Session session = this.openSession(); beginTransaction(); Criteria criteria = session.createCriteria(clazz); Iterator it = restrictions.iterator(); while (it.hasNext()) criteria.add((Criterion) it.next()); objs = criteria.list(); if (autoCommit) commitTransaction(); } catch (HibernateException ex) { rollbackTransaction(); log.error("Fail to find objects by criterions", ex); throw new DaoException("Fail to find objects by criterions", ex); } finally { if (autoCloseSession) closeSession(); } return objs; }
tx = getSession(true).beginTransaction();
出错
错误信息如下:
14:54:25,781 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@1a0df30
java.lang.Throwable: STACKTRACE
at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:290)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:417)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:82)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at com.testprj.common.dao.HibernateSessionManager.beginTransaction(HibernateSessionManager.java:120)
at com.testprj.common.dao.HibernateDaoImpl.beginTransaction(HibernateDaoImpl.java:149)
at com.testprj.common.dao.HibernateDaoImpl.findByCriterions(HibernateDaoImpl.java:372)
at com.testprj.persistence.ss.dao.hbmimpl.MenuDAOImpl.findByRowID(MenuDAOImpl.java:59)
at com.testprj.domain.base.service.MenuServiceImpl.findByRowID(MenuServiceImpl.java:73)
at com.testprj.ui.base.ss.WinMenuEdit.getTMenuById(WinMenuEdit.java:311)
at com.testprj.ui.base.ss.WinMenuEdit.loadMenu(WinMenuEdit.java:173)
at com.testprj.ui.base.ss.WinMenuEdit.afterCompose(WinMenuEdit.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:109)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:174)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.webapp.DefaultLoginPageGeneratingFilter.doFilterHttp(DefaultLoginPageGeneratingFilter.java:86)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:277)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:277)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
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:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Unknown Source)
奇怪的是并非每次执行都有错误,偶尔也会成功!
目前采用的是webserver的JNDI连接池。
搜了很久,有兄弟建议用c3p0连接池,http://bjzhanghao.cnblogs.com/archive/2004/12/10/75145.html 19楼。
于是修改spring-hibernate配置如下:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"><ref bean="dataSource" /></property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop> <prop key="hibernate.show_sql">false</prop> <!-- add for c3p0 连接池 --> <prop key="hibernate.c3p0.min_size">5</prop> <prop key="hibernate.c3p0.max_size">20</prop> <prop key="hibernate.c3p0.timeout">1800</prop> <prop key="hibernate.c3p0.max_statements">50</prop> </props> </property> <property name="configLocation" value="classpath:/config/hibernate/hibernate.cfg.xml"/> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property></bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <tx:annotation-driven transaction-manager="transactionManager" />
依然没有解决,错误依旧。
更有兄弟说只是调试信息,没影响。http://hbird.vicp.net/viewthread.php?action=printable&tid=2157
求指点!
-----------------------------------------------------------------------------------
已解决:
我试了一下,如果不用JNDI,直接在spring里写datasource的配置,则不会出现该错误。
rain2005 (中级程序员) 2008-12-18
的解决方法:
现在使用的是JBOSS的dataSource,不是使用的c3p0当然报错拉
两种方式:
1、采用c3p0数据源配置连接池:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>com.ibm.db2.jcc.DB2Driver</value> </property> <property name="jdbcUrl"> <value>jdbc:db2://172.21.21.2:50000/HOSPDB</value> </property> <property name="user"> <value>db2admin</value> </property> <property name="password"> <value>dhcc</value> </property> ...... </bean>
2、如果使用JNDI的话,transactionManager也得改成jboss提供的事务管理器。具体配置可以参考spring文档中的JTA事务管理。
发表评论
-
对J2EE应用系统分层设计的思考
2009-02-19 10:29 1136J2EE分层设计是Java企业 ... -
将Spring、Hibernate与WAS一起使用(3)
2009-01-07 11:22 1390使用 Hibernate Hibernate 是 POJO 的 ... -
将Spring、Hibernate与WAS一起使用(2)
2009-01-07 11:20 2035使用 Spring 处理事务 WebSphere Applic ... -
将Spring、Hibernate与WAS一起使用(1)
2009-01-07 10:57 1153如果您考虑将 Spring 或 Hibernate 与 IBM ... -
c3p0连接池配置
2008-12-18 16:44 1854<!-- 采取c3p0连接池 --> <b ... -
spring+hibernate annotation 在JBoss下的错误处理
2008-12-17 14:05 6825spring+hibernate,基于annota ... -
J2ee的异常处理
2008-12-03 19:26 1107一种观点: 一、发生 ...
相关推荐
6. **集成Hibernate与Oracle**: 在J2EE应用中使用Hibernate连接Oracle数据库,需要在项目的类路径中包含以上提到的jar文件,并在Hibernate的配置文件(如hibernate.cfg.xml)中指定Oracle的JDBC驱动类以及数据库连接...
在本例中,标题提到的"jboss、eclipse的jpa连接mysql不成熟的例子"可能指的是在尝试配置Eclipse开发环境,使用JPA与JBoss应用服务器连接MySQL数据库时遇到了问题。Eclipse是一个强大的Java集成开发环境,提供了对JPA...
8. **日志和调试**:遇到问题时,查看`JBOSS_HOME/server/default/log`目录下的日志文件,如server.log,可以帮助定位错误。同时,可以调整服务器配置以启用更详细的日志输出。 9. **安全性配置**:默认情况下,...
3. **服务初始化**:JBoss根据配置文件加载并初始化各种服务,如EJB容器、Web服务器( Undertow 或 Tomcat )、JMS消息队列、持久化服务(Hibernate)等。 4. **模块加载**:JBoss模块系统会加载应用所需的类库和...
然而,有时候在使用Hibernate的过程中,可能会遇到一些问题,比如由JBoss Tools生成的XML文件出现bug。这个问题可能涉及到多个方面,包括XML文件的语法错误、配置错误或者是工具自身的兼容性问题。下面将详细探讨...
2. Hibernate Console Configuration:配置完成后,可以在`Hibernate Configurations`视图中看到配置项,确认数据库连接成功并且能够列出数据库中的表。 3. 代码生成:利用Hibernate Tools的`Hibernate Code ...
<property name="hibernate.connection.datasource">java:jboss/datasources/ExampleDS ``` 2. **禁用JNDI绑定:**如果应用并不打算通过JNDI来获取SessionFactory,可以在配置文件中显式地禁用JNDI绑定。 ```xml ...
2. 数据库驱动:Hibernate需要相应的数据库驱动才能连接到特定的数据库,例如`mysql-connector-java.jar`(针对MySQL),`ojdbc6.jar`(针对Oracle)等。具体使用哪个取决于你的项目所使用的数据库。 3. JTA(Java ...
### Eclipse下配置与使用Hibernate Tools详解 #### 引言 Hibernate作为一款优秀的对象关系映射(ORM)框架,简化了Java应用与数据库交互的过程。在Eclipse开发环境中,通过使用Hibernate Tools插件,开发者能够更...
8. **jboss-logging.jar**:为 Hibernate 提供日志服务,特别是在使用 JBoss 应用服务器时。 9. **cglib-nodep.jar**:Hibernate 在某些情况下可能需要 CGLIB 来创建实体类的代理对象,实现方法拦截。 10. **...
5. **jboss-logging.jar**:提供日志服务,Hibernate通过它来记录各种调试和错误信息。你可以根据项目需求配置不同的日志实现,如log4j或slf4j。 6. **dom4j.jar**:一个用于处理XML文档的库,Hibernate使用它来...
8. **jboss-logging.jar**:这是JBoss的日志框架,Hibernate使用它来记录各种调试和错误信息。 9. **slf4j-api.jar 和 slf4j-simple.jar (或 logback-classic.jar)**:SLF4J(Simple Logging Facade for Java)是一...
- `hibernate.connection.url`设置Oracle数据库的连接URL,例如`jdbc:oracle:thin:@localhost:1521:orcl`。 - `hibernate.connection.username`和`hibernate.connection.password`分别设置数据库用户名和密码。 -...
6. **jboss-logging.jar**:日志处理库,Hibernate使用它进行各种调试和错误信息的记录。 7. **其他依赖库**:如dom4j、slf4j、cglib、asm等,它们是Hibernate运行时需要的辅助库,分别用于XML处理、日志服务、动态...
1. **安装与配置**:文档详细介绍了如何在各种操作系统环境下安装JBoss,以及如何进行适当的系统配置,确保服务器稳定运行。这包括网络设置、内存优化、安全策略配置等。 2. **管理与监控**:用户可以学习到如何...
在描述中提到,Hibernate在J2EE应用中的使用通常伴随着容器,如Tomcat或JBoss,因为容器能提供事务管理、线程安全性和其他服务。然而,当需要在没有容器环境的Java SE应用中使用Hibernate时,我们需要自行处理这些...
- 配置Hibernate项目:在Eclipse中设置Hibernate的配置文件(hibernate.cfg.xml),指定数据库连接信息等。 - 创建数据库表:在数据库中创建所需的表结构。 - 生成实体类和映射文件:通过Eclipse插件,选择数据库表...
3. **数据库连接池**:如`c3p0-*.jar`, `dbcp-*.jar` 或 `hikaricp-*.jar` - Hibernate需要一个连接池来有效地管理数据库连接,提高性能和资源利用效率。C3P0、Apache DBCP 和 HikariCP 都是常见的选择。 4. **JDBC...
你可以将打包好的`.war`、`.ear`或`.jar`文件放入`standalone/deployments`目录下,JBoss会自动检测并部署这些文件。 ### 2.2 使用管理控制台 通过浏览器访问`http://localhost:9990`,使用默认的用户名和密码(如...