[JBoss jBPM] - Containermanaged EJB / jBPM problems
by cwad0000
I want to create a stateless container managed EJB 2.1.
I follow the user guide, and the deployProcessess() is exactly as described in the user guide.
When I comment out jbpmContext.close(); I get a warning about unclosed connection (see below), when I leave it in I get hard errors (see below).
Can anyone please point out where I go wrong?
| public void deployProcessess() throws java.io.IOException {
|
| JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
|
| try {
|
| String xmlFile = "someprocess.xml";
|
| log.debug(logPrefix + "deployProcess: Attempt to load " + xmlFile);
| //load and parse the xml file
| java.io.InputStream is = this.getClass().getResourceAsStream(xmlFile);
|
| ProcessDefinition processDefinition = ProcessDefinition.parseXmlInputStream(is);
|
| // Save the process definition in the database
| jbpmContext.deployProcessDefinition(processDefinition);
| }
| } finally {
| jbpmContext.close();
| }
| }
| }
|
jbpm.cfg.xml
| <jbpm-configuration>
|
| <jbpm-context>
| <service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory">
| <field name="isTransactionEnabled"><false /></field>
| </service>
|
| <service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
| <service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
| <service name="logging" factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
| <service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
| </jbpm-context>
|
| <!-- configuration resource files pointing to default configuration files in jbpm-{version}.jar -->
| <string name="resource.hibernate.cfg.xml" value="hibernate.cfg.xml" />
| <!-- <string name="resource.hibernate.properties" value="hibernate.properties" /> -->
| <string name="resource.business.calendar" value="org/jbpm/calendar/jbpm.business.calendar.properties" />
| <string name="resource.default.modules" value="org/jbpm/graph/def/jbpm.default.modules.properties" />
| <string name="resource.converter" value="org/jbpm/db/hibernate/jbpm.converter.properties" />
| <string name="resource.action.types" value="org/jbpm/graph/action/action.types.xml" />
| <string name="resource.node.types" value="org/jbpm/graph/node/node.types.xml" />
| <string name="resource.parsers" value="org/jbpm/jpdl/par/jbpm.parsers.xml" />
| <string name="resource.varmapping" value="org/jbpm/context/exe/jbpm.varmapping.xml" />
|
| <bean name="jbpm.task.instance.factory" class="org.jbpm.taskmgmt.impl.DefaultTaskInstanceFactoryImpl" singleton="true" />
| <bean name="jbpm.variable.resolver" class="org.jbpm.jpdl.el.impl.JbpmVariableResolver" singleton="true" />
| <long name="jbpm.msg.wait.timout" value="5000" singleton="true" />
|
| </jbpm-configuration>
|
Message when I commented out jbpmContext.close();
| 09:41:38,625 INFO : RDBMS: MySQL, version: 5.0.19-nt-log
| 09:41:38,625 INFO : JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
| 09:41:38,625 INFO : Using dialect: org.hibernate.dialect.MySQLDialect
| 09:41:38,641 INFO : Using default transaction strategy (direct JDBC transactions)
| 09:41:38,641 INFO : No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
| 09:41:38,641 INFO : Automatic flush during beforeCompletion(): disabled
| 09:41:38,641 INFO : Automatic session close at end of transaction: disabled
| 09:41:38,641 INFO : JDBC batch size: 15
| 09:41:38,641 INFO : JDBC batch updates for versioned data: disabled
| 09:41:38,641 INFO : Scrollable result sets: enabled
| 09:41:38,641 INFO : JDBC3 getGeneratedKeys(): enabled
| 09:41:38,641 INFO : Connection release mode: auto
| 09:41:38,641 INFO : Maximum outer join fetch depth: 2
| 09:41:38,641 INFO : Default batch fetch size: 1
| 09:41:38,641 INFO : Generate SQL with comments: disabled
| 09:41:38,641 INFO : Order SQL updates by primary key: disabled
| 09:41:38,641 INFO : Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
| 09:41:38,641 INFO : Using ASTQueryTranslatorFactory
| 09:41:38,641 INFO : Query language substitutions: {}
| 09:41:38,641 INFO : Second-level cache: enabled
| 09:41:38,641 INFO : Query cache: disabled
| 09:41:38,641 INFO : Cache provider: org.hibernate.cache.EhCacheProvider
| 09:41:38,641 INFO : Optimize cache for minimal puts: disabled
| 09:41:38,657 INFO : Structured second-level cache entries: disabled
| 09:41:38,657 INFO : Statistics: disabled
| 09:41:38,657 INFO : Deleted entity synthetic identifier rollback: disabled
| 09:41:38,657 INFO : Default entity-mode: POJO
| 09:41:38,657 INFO : building session factory
| 09:41:39,641 INFO : Not binding factory to JNDI, no JNDI name configured
| 09:41:39,656 INFO : Checking 28 named queries
| 09:41:39,735 TRACE: getPrincipal, principal=null
| 09:41:39,735 TRACE: Begin isValid, principal:null, cache info: org.jboss.security.plugins.JaasSecurityManager$DomainInfo@4479b2[Subject(15564636).principals=org.jboss.security.SimplePrincipal(a)5487610(root),credential.class=null,expirationTime=1158134690868]
| 09:41:39,735 TRACE: Begin validateCache, info=org.jboss.security.plugins.JaasSecurityManager$DomainInfo@4479b2[Subject(15564636).principals=org.jboss.security.SimplePrincipal(a)5487610(root),credential.class=null,expirationTime=1158134690868];credential.class=null
| 09:41:39,735 TRACE: End validateCache, isValid=true
| 09:41:39,735 TRACE: End isValid, true
| 09:41:41,031 INFO : Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@1da30c3
| java.lang.Throwable: STACKTRACE
|
| at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:333)
|
| at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:482)
|
| at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:894)
|
| at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:73)
|
| at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:69)
|
| at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:304)
|
| at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:109)
|
| at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:134)
|
| at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
|
| at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1236)
|
| at org.jbpm.persistence.db.DbPersistenceService.getSession(DbPersistenceService.java:98)
|
| at org.jbpm.persistence.db.DbPersistenceService.getGraphSession(DbPersistenceService.java:217)
|
| at org.jbpm.JbpmContext.getGraphSession(JbpmContext.java:537)
|
| at org.jbpm.JbpmContext.deployProcessDefinition(JbpmContext.java:173)
|
| at com.package.app.workflow.WorkflowManagerBean.deployProcessess(WorkflowManagerBean.java:146)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
|
| at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
|
| at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
|
| at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
|
| at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
|
| at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
|
| at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
|
| at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
|
| at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
|
| at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
|
| at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
|
| at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
|
| at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
|
| at org.jboss.ejb.Container.invoke(Container.java:873)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
|
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
|
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
|
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
|
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
|
| at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
|
| at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
|
| at sun.rmi.transport.Transport$1.run(Transport.java:153)
|
| at java.security.AccessController.doPrivileged(Native Method)
|
| at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
|
| at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
|
| at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
|
| at java.lang.Thread.run(Thread.java:595)
|
| 09:41:41,062 TRACE: popRunAsIdentity, runAs=null
| 09:41:41,062 TRACE: popSubjectContext, sc=org.jboss.security.SecurityAssociation$SubjectContext@6b1066{principal=null,subject=null}
|
Message when I use jbpmContext.close();
| 09:50:55,108 INFO : RDBMS: MySQL, version: 5.0.19-nt-log
| 09:50:55,108 INFO : JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
| 09:50:55,108 INFO : Using dialect: org.hibernate.dialect.MySQLDialect
| 09:50:55,108 INFO : Using default transaction strategy (direct JDBC transactions)
| 09:50:55,124 INFO : No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
| 09:50:55,124 INFO : Automatic flush during beforeCompletion(): disabled
| 09:50:55,124 INFO : Automatic session close at end of transaction: disabled
| 09:50:55,124 INFO : JDBC batch size: 15
| 09:50:55,124 INFO : JDBC batch updates for versioned data: disabled
| 09:50:55,124 INFO : Scrollable result sets: enabled
| 09:50:55,124 INFO : JDBC3 getGeneratedKeys(): enabled
| 09:50:55,124 INFO : Connection release mode: auto
| 09:50:55,124 INFO : Maximum outer join fetch depth: 2
| 09:50:55,124 INFO : Default batch fetch size: 1
| 09:50:55,124 INFO : Generate SQL with comments: disabled
| 09:50:55,124 INFO : Order SQL updates by primary key: disabled
| 09:50:55,124 INFO : Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
| 09:50:55,124 INFO : Using ASTQueryTranslatorFactory
| 09:50:55,124 INFO : Query language substitutions: {}
| 09:50:55,140 INFO : Second-level cache: enabled
| 09:50:55,140 INFO : Query cache: disabled
| 09:50:55,140 INFO : Cache provider: org.hibernate.cache.EhCacheProvider
| 09:50:55,140 INFO : Optimize cache for minimal puts: disabled
| 09:50:55,140 INFO : Structured second-level cache entries: disabled
| 09:50:55,140 INFO : Statistics: disabled
| 09:50:55,140 INFO : Deleted entity synthetic identifier rollback: disabled
| 09:50:55,140 INFO : Default entity-mode: POJO
| 09:50:55,140 INFO : building session factory
| 09:50:56,077 INFO : Not binding factory to JNDI, no JNDI name configured
| 09:50:56,077 INFO : Checking 28 named queries
| 09:50:56,155 TRACE: getPrincipal, principal=null
| 09:50:56,155 TRACE: Begin isValid, principal:null, cache info: org.jboss.security.plugins.JaasSecurityManager$DomainInfo@4479b2[Subject(15564636).principals=org.jboss.security.SimplePrincipal(a)5487610(root),credential.class=null,expirationTime=1158134690868]
| 09:50:56,155 TRACE: Begin validateCache, info=org.jboss.security.plugins.JaasSecurityManager$DomainInfo@4479b2[Subject(15564636).principals=org.jboss.security.SimplePrincipal(a)5487610(root),credential.class=null,expirationTime=1158134690868];credential.class=null
| 09:50:56,155 TRACE: End validateCache, isValid=true
| 09:50:56,155 TRACE: End isValid, true
| 09:50:57,671 ERROR: JDBC commit failed
| java.sql.SQLException: You cannot commit during a managed transaction!
|
| at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:432)
|
| at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:331)
|
| at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
|
| at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
|
| at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:162)
|
| at org.jbpm.svc.Services.close(Services.java:211)
|
| at org.jbpm.JbpmContext.close(JbpmContext.java:139)
|
| at our.package.app.workflow.WorkflowManagerBean.deployProcessess(WorkflowManagerBean.java:149)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
|
| at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
|
| at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
|
| at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
|
| at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
|
| at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
|
| at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
|
| at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
|
| at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
|
| at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
|
| at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
|
| at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
|
| at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
|
| at org.jboss.ejb.Container.invoke(Container.java:873)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
|
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
|
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
|
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
|
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
|
| at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
|
| at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
|
| at sun.rmi.transport.Transport$1.run(Transport.java:153)
|
| at java.security.AccessController.doPrivileged(Native Method)
|
| at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
|
| at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
|
| at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
|
| at java.lang.Thread.run(Thread.java:595)
|
| 09:50:57,905 INFO : org.jbpm.persistence.JbpmPersistenceException: couldn't commit hibernate session
| 09:50:57,905 INFO : at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:172)
| 09:50:57,905 INFO : at org.jbpm.svc.Services.close(Services.java:211)
| 09:50:57,921 INFO : at org.jbpm.JbpmContext.close(JbpmContext.java:139)
| 09:50:57,921 INFO : at our.package.app.workflow.WorkflowManagerBean.deployProcessess(WorkflowManagerBean.java:149)
| 09:50:57,921 INFO : at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 09:50:57,921 INFO : at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| 09:50:57,921 INFO : at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 09:50:57,921 INFO : at java.lang.reflect.Method.invoke(Method.java:585)
| 09:50:57,921 INFO : at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
| 09:50:57,921 INFO : at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
| 09:50:57,921 INFO : at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
| 09:50:57,921 INFO : at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
| 09:50:57,921 INFO : at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
| 09:50:57,921 INFO : at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
| 09:50:57,921 INFO : at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
| 09:50:57,921 INFO : at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
| 09:50:57,937 INFO : at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
| 09:50:57,937 INFO : at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
| 09:50:57,937 INFO : at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
| 09:50:57,937 INFO : at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
| 09:50:57,937 INFO : at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
| 09:50:57,937 INFO : at org.jboss.ejb.Container.invoke(Container.java:873)
| 09:50:57,937 INFO : at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 09:50:57,937 INFO : at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| 09:50:57,937 INFO : at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 09:50:57,937 INFO : at java.lang.reflect.Method.invoke(Method.java:585)
| 09:50:57,937 INFO : at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
| 09:50:57,937 INFO : at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
| 09:50:57,937 INFO : at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
| 09:50:57,952 INFO : at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
| 09:50:57,952 INFO : at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
| 09:50:57,952 INFO : at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
| 09:50:57,952 INFO : at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
| 09:50:57,952 INFO : at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 09:50:57,952 INFO : at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| 09:50:57,952 INFO : at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 09:50:57,952 INFO : at java.lang.reflect.Method.invoke(Method.java:585)
| 09:50:57,952 INFO : at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
| 09:50:57,952 INFO : at sun.rmi.transport.Transport$1.run(Transport.java:153)
| 09:50:57,952 INFO : at java.security.AccessController.doPrivileged(Native Method)
| 09:50:57,952 INFO : at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
| 09:50:57,952 INFO : at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
| 09:50:57,952 INFO : at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
| 09:50:57,968 INFO : at java.lang.Thread.run(Thread.java:595)
| 09:50:57,968 INFO : Caused by: org.hibernate.TransactionException: JDBC commit failed
| 09:50:57,968 INFO : at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:130)
| 09:50:57,968 INFO : at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:162)
| 09:50:57,968 INFO : ... 43 more
| 09:50:57,968 INFO : Caused by: java.sql.SQLException: You cannot commit during a managed transaction!
| 09:50:57,968 INFO : at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:432)
| 09:50:57,968 INFO : at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:331)
| 09:50:57,968 INFO : at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
| 09:50:57,968 INFO : at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
| 09:50:57,968 INFO : ... 44 more
| 09:50:57,968 ERROR: problem closing service 'persistence'
| org.jbpm.persistence.JbpmPersistenceException: couldn't commit hibernate session
|
| at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:172)
|
| at org.jbpm.svc.Services.close(Services.java:211)
|
| at org.jbpm.JbpmContext.close(JbpmContext.java:139)
|
| at our.package.app.workflow.WorkflowManagerBean.deployProcessess(WorkflowManagerBean.java:149)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
|
| at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
|
| at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
|
| at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
|
| at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
|
| at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
|
| at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
|
| at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
|
| at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
|
| at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
|
| at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
|
| at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
|
| at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
|
| at org.jboss.ejb.Container.invoke(Container.java:873)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
|
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
|
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
|
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
|
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
|
| at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
|
| at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
|
| at sun.rmi.transport.Transport$1.run(Transport.java:153)
|
| at java.security.AccessController.doPrivileged(Native Method)
|
| at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
|
| at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
|
| at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
|
| at java.lang.Thread.run(Thread.java:595)
|
| Caused by: org.hibernate.TransactionException: JDBC commit failed
|
| at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:130)
|
| at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:162)
|
| ... 43 more
|
| Caused by: java.sql.SQLException: You cannot commit during a managed transaction!
|
| at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:432)
|
| at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:331)
|
| at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
|
| at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
|
| ... 44 more
|
| 09:50:58,140 TRACE: popRunAsIdentity, runAs=null
| 09:50:58,140 TRACE: popSubjectContext, sc=org.jboss.security.SecurityAssociation$SubjectContext@18e282c{principal=null,subject=null}
| 09:50:58,140 ERROR: RuntimeException in method: public abstract void our.package.app.workflow.WorkflowManager.deployProcessess() throws java.io.IOException,java.rmi.RemoteException:
| org.jbpm.JbpmException: problem closing services {persistence=org.jbpm.persistence.JbpmPersistenceException: couldn't commit hibernate session}
|
| at org.jbpm.svc.Services.close(Services.java:223)
|
| at org.jbpm.JbpmContext.close(JbpmContext.java:139)
|
| at our.package.app.workflow.WorkflowManagerBean.deployProcessess(WorkflowManagerBean.java:149)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
|
| at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
|
| at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
|
| at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
|
| at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
|
| at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
|
| at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
|
| at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
|
| at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
|
| at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
|
| at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
|
| at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
|
| at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
|
| at org.jboss.ejb.Container.invoke(Container.java:873)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
|
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
|
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
|
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
|
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
|
| at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
|
| at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
| at java.lang.reflect.Method.invoke(Method.java:585)
|
| at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
|
| at sun.rmi.transport.Transport$1.run(Transport.java:153)
|
| at java.security.AccessController.doPrivileged(Native Method)
|
| at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
|
| at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
|
| at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
|
| at java.lang.Thread.run(Thread.java:595)
|
| Caused by: org.jbpm.persistence.JbpmPersistenceException: couldn't commit hibernate session
|
| at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:172)
|
| at org.jbpm.svc.Services.close(Services.java:211)
|
| ... 42 more
|
| Caused by: org.hibernate.TransactionException: JDBC commit failed
|
| at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:130)
|
| at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:162)
|
| ... 43 more
|
| Caused by: java.sql.SQLException: You cannot commit during a managed transaction!
|
| at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:432)
|
| at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:331)
|
| at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
|
| at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
|
| ... 44 more
|
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3971206#3971206
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3971206
19 years, 7 months
[Clustering/JBoss] - Re: ejb proxies only contain nodes at deploy time
by bugumala
"bstansberry(a)jboss.com" wrote : I'm confused; please try to explain again exactly what happens.
Ok, I'll try to explain. Whenever a change is made to the cluster, adding a node or one node dies, the client proxies aren't informed. If I'm correctly informed this should happen. Even jndi lookup results in the same proxies as before the change in the cluster config.
"bstansberry(a)jboss.com" wrote : What does "start the client from Server 1" mean? Please describe how your client interacts with the servers.
There is a webserver started on each server holding the java webstart client. Depending on which server is used to download the client the behavior is different as I described. The client calls stateless ejbs on the server and these are quite frequently looked up from jndi. The problem is that the resulting proxy only contains the nodes available to the server when it was deployed.
"bstansberry(a)jboss.com" wrote : What does "keeps calling the dead server" mean? Numerous times? Or once, and that call takes a long time to fail?
Here is some Ethereal capture made after Server1 (192.168.1.116) was shut down. This is part of the response from Server2
servlet://192.168.1.116:80/servlet-invoker/ServerInvokerServletpt.$servlet-invoker/ServerInvokerServlett..servlett.?servlet://192.168.1.116:80/servlet-invoker/ServerInvokerServletsq.~.....Pt.
| 192.168.1.117t.?servlet://192.168.1.117:80/serw.vlet-invoker/ServerInvokerServletpt.$servlet-invoker
| /ServerInvokerServlett..servlett.?servlet://192.168.1.117:80/servlet-invoker/ServerInvokerServletxxsr.-org.jboss.ha.framework.interfaces.RandomRobin...........xpp..@.x
|
As I understand the proxy is informed that both server is still alive and it uses it numerous times, each time with a timeout that takes a long time to fail.
Even if this is a ha-jndi matter we are somewhat confused. The first problem when only one server is used may be because we only get the local jndi. But the other case where we get both servers in the proxy is weird. Shouldn't it catch the death of the other node and reflect it to the proxies?
/Jon
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3971205#3971205
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3971205
19 years, 7 months
[EJB 3.0] - Exception handling
by martin ganserer
Hello experts,
could you please take a look at my code. I am really not sure if my exception handling is correct or maybe completely wrong.
As you can see I catch every exception log what happened and throw a new RuntimeException!
Could you give me a hand how I should implement exception handling in my DAO beans?
@Stateless
| public class CustomerServiceBean implements CustomerService, CustomerServiceRemote
| {
| private @PersistenceContext(unitName = "order") EntityManager em;
| private static Logger logger = Logger.getLogger(Customer.class);
|
| /**
| * Persist customer object
| * @param customer the customer to persist
| * @return the persisted customer object
| * @throws GenericServiceException
| */
| @PermitAll
| public Customer persistCustomer(Customer customer) throws GenericServiceException
| {
| if(customer == null)
| {
| String errorMessage = "Can not persist empty object!";
| logger.warn(errorMessage);
| throw new GenericServiceException(errorMessage);
| }
|
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Persist customer " + customer.toString() + ".");
|
| em.persist(customer);
|
| if(logger.isDebugEnabled())
| logger.debug("Customer " + customer.toString() + " with id " + customer.getId() + " persisted!");
|
| return customer;
| }
| catch(Throwable e)
| {
| logger.error("Could not persist customer " + customer.toString(),e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Merge customer object
| * @param customer the customer to persist
| * @return the merged customer object
| * @throws GenericServiceException
| */
| @PermitAll
| public Customer mergeCustomer(Customer customer) throws GenericServiceException
| {
| if(customer == null)
| {
| String errorMessage = "Can not merge empty object!";
| logger.warn(errorMessage);
| throw new GenericServiceException(errorMessage);
| }
|
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Merge customer " + customer.toString() + ".");
|
| return em.merge(customer);
|
| }
| catch(Throwable e)
| {
| logger.error("Could not merge customer " + customer.toString(),e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Find customer
| * @param id
| * @return the customer object
| * @throws GenericServiceException
| */
| @PermitAll
| public Customer findCustomerById(int id) throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Find customer " + id);
|
| return em.find(Customer.class, id);
| }
| catch(Throwable e)
| {
| logger.error("Could not find customer " + id,e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Find customer
| * @param id
| * @param mustExist if true an exception will be thrown if the object does not exist.
| * @return a customer object.
| * @throws GenericServiceException
| */
| @PermitAll
| public Customer findCustomerById(int id, boolean mustExist) throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Find customer " + id);
|
| if(mustExist)
| {
| Customer customer = new Customer(id);
| em.refresh(customer);
| return customer;
| }
| else
| return em.find(Customer.class, id);
| }
| catch(Throwable e)
| {
| logger.error("Could not find customer " + id,e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Find customer
| * @param customer the customer to search for
| * @return the customer object
| * @throws GenericServiceException
| */
| @PermitAll
| public Customer findCustomerById(Customer customer) throws GenericServiceException
| {
| if(customer == null)
| {
| String errorMessage = "Can not search by using an empty object!";
| logger.warn(errorMessage);
| throw new GenericServiceException(errorMessage);
| }
|
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Find customer " + customer.getId());
|
| return em.find(Customer.class,customer.getId());
| }
| catch(Throwable e)
| {
| logger.error("Could not find customer " + customer.getId(),e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Remove all customers
| * @return the number of removed customer objects
| * @throws GenericServiceException
| */
| @PermitAll
| public long removeAllCustomers() throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Remove all customer objects!");
|
| return em.createQuery("delete from Customer").executeUpdate();
| }
| catch(Throwable e)
| {
| logger.error("Could not remove all customer objects!",e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Get all customers
| * @return a collection of customers objects
| * @throws GenericServiceException
| */
| @PermitAll
| public Collection<Customer> getAllCustomers() throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Find all customer objects!");
|
| return (Collection<Customer>) em.createQuery("from Customer").getResultList();
| }
| catch(Throwable e)
| {
| logger.error("Could not find customer objects!",e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Get all customers
| * @param noOfObjects
| * @param startIndex
| * @return a collection of customer objects
| * @throws GenericServiceException
| */
| @PermitAll
| public Collection<Customer> getAllCustomers(int noOfObjects, int startIndex) throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Find all customer objects with paging!");
|
| Query query = em.createQuery("from Customer");
| query.setMaxResults(noOfObjects);
| query.setFirstResult(startIndex);
| return (Collection<Customer>) query.getResultList();
| }
| catch(Throwable e)
| {
| logger.error("Could not find customer objects with paging!",e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Remove customer
| * @param id the identifier of the object to be removed
| * @throws GenericServiceException
| */
| @PermitAll
| public void removeCustomer(int id) throws GenericServiceException
| {
| Customer customer;
|
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Remove customer " + id);
|
| customer = em.find(Customer.class,id);
| }
| catch(Throwable e)
| {
| logger.error("Could not remove customer " + id,e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| if(customer == null)
| {
| String errorMessage = "Can not remove a non existing object!";
| logger.warn(errorMessage);
| throw new GenericServiceException(errorMessage);
| }
|
| try
| {
| em.remove(customer);
| }
| catch(Throwable e)
| {
| logger.error("Could not remove customer " + id,e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Get customer
| * @param name
| * @return the customer object
| * @throws GenericServiceException
| */
| @PermitAll
| public Customer getCustomerByName(String name) throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Search for customer!");
|
| String ejbQL = " from Customer a where a.name = :param1";
| Query query = em.createQuery(ejbQL);
| query.setParameter("param1",name);
|
| return (Customer) query.getSingleResult();
| }
| catch(Throwable e)
| {
| logger.error("Could not search for customer!",e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Search customer
| * @param name
| * @return a collection of customer objects
| * @throws GenericServiceException
| */
| @PermitAll
| public Collection<Customer> searchCustomerByName(String name) throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Search for customers!");
|
| String ejbQL = " from Customer a where a.name like :param1";
| Query query = em.createQuery(ejbQL);
| query.setParameter("param1",name);
|
| return (Collection<Customer>) query.getResultList();
| }
| catch(Throwable e)
| {
| logger.error("Could not search for customers!",e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Search for customers objects via an ejb query string
| * @param ejbQL the ejb query string
| * @return a collection of customer objects
| * @throws GenericServiceException
| */
| @PermitAll
| public Collection<Customer> searchCustomers(String ejbQL) throws GenericServiceException
| {
| if(ejbQL == null || ejbQL.equals(""))
| {
| String errorMessage = "Query string must not be empty!";
| logger.warn(errorMessage);
| throw new GenericServiceException(errorMessage);
| }
|
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Search for customer objects!");
|
| return (Collection<Customer>) em.createQuery(ejbQL).getResultList();
| }
| catch(Throwable e)
| {
| logger.error("Could not search for customers by using query: " + ejbQL,e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Search for customers objects via an ejb query string
| * @param ejbQL
| * @param noOfObjects
| * @param startIndex
| * @return a collection of customer objects
| * @throws GenericServiceException
| */
| @PermitAll
| public Collection<Customer> searchCustomers(String ejbQL, int noOfObjects, int startIndex) throws GenericServiceException
| {
| if(ejbQL == null || ejbQL.equals(""))
| {
| String errorMessage = "Query string must not be empty!";
| logger.warn(errorMessage);
| throw new GenericServiceException(errorMessage);
| }
|
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Search for customer objects!");
|
| Query query = em.createQuery(ejbQL);
| query.setMaxResults(noOfObjects);
| query.setFirstResult(startIndex);
| return (Collection<Customer>) query.getResultList();
| }
| catch(Throwable e)
| {
| logger.error("Could not search for customers by using query: " + ejbQL,e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Check if customer already exists
| * @param id
| * @return true if the customer already exists
| * @throws GenericServiceException
| */
| @PermitAll
| public boolean checkCustomer(int id) throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Check customer " + id + "!");
|
| long counter = (Long) em.createQuery("select count(a) from Customer a where a.id = :param").setParameter("param",id).getSingleResult();
|
| if(counter == 0)
| return false;
|
| return true;
| }
| catch(Throwable e)
| {
| logger.error("Could not check customer!",e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Remove a list of customers
| * @param customers a list of objects to be removed
| * @throws GenericServiceException
| */
| @PermitAll
| public void removeCustomers(Collection<Customer> customers) throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Remove a list of customers!");
|
| for(Customer listItem : customers)
| {
| Customer customer = em.find(Customer.class,listItem.getId());
| em.remove(customer);
| }
| }
| catch(Throwable e)
| {
| logger.error("Could not remove customers!",e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Persist a list of customers
| * @param customers a list of objects to be persistet
| * @return a list of persisted customers
| * @throws GenericServiceException
| */
| @PermitAll
| public Collection<Customer> persistCustomers(Collection<Customer> customers) throws GenericServiceException
| {
| Collection<Customer> itemList = new ArrayList();
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Persist a list of customers!");
|
| for(Customer item : customers)
| {
| em.persist(item);
| itemList.add(item);
| }
| return itemList;
| }
| catch(Throwable e)
| {
| logger.error("Could not persist customers!",e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Merge a list of customers
| * @param customers a list of objects to be merged
| * @return a list of merged customers
| * @throws GenericServiceException
| */
| @PermitAll
| public Collection<Customer> mergeCustomers(Collection<Customer> customers) throws GenericServiceException
| {
| Collection<Customer> itemList = new ArrayList();
| if(logger.isDebugEnabled())
| logger.debug("Merge a list of customers!");
|
| try
| {
| for(Customer item : customers)
| {
| em.merge(item);
| itemList.add(item);
| }
| return itemList;
| }
| catch(Throwable e)
| {
| logger.error("Could not merge customers!",e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Count customers
| * @return the number of persistent customers
| * @throws GenericServiceException
| */
| @PermitAll
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public Long countCustomers() throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Count customers!");
|
| return (Long) em.createQuery("select count (a) from Customer a").getSingleResult();
| }
| catch(Throwable e)
| {
| logger.error("Could not count customers!",e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Count customers
| * @param criteria the query criteria(s)
| * @return the number of persistent customers
| * @throws GenericServiceException
| */
| @PermitAll
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public Long countCustomers(String criteria) throws GenericServiceException
| {
| if(criteria == null)
| criteria = "";
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Count customers!");
|
| if(criteria.toLowerCase().contains("where"))
| return (Long) em.createQuery("select count (a) from Customer a " + criteria).getSingleResult();
| else
| return (Long) em.createQuery("select count (a) from Customer a where " + criteria).getSingleResult();
| }
| catch(Throwable e)
| {
| logger.error("Could not count customers by using criteria: " + criteria,e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| /**
| * Get country of this customer
| * @param id
| * @return the country of this customer
| * @throws GenericServiceException
| */
| @PermitAll
| public Country getCountryOfCustomer(int id) throws GenericServiceException
| {
| try
| {
| if(logger.isDebugEnabled())
| logger.debug("Find country of customer " + id);
|
| return (Country) em.createQuery("select b from Customer a join a.country b where a.id =" + id).getSingleResult();
| }
| catch(Throwable e)
| {
| logger.error("Could not find country of customer " + id,e);
| throw new GenericServiceException(e.getMessage(),e.getCause());
| }
| }
|
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3971202#3971202
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3971202
19 years, 7 months