[EJB/JBoss] - custom ejb exception handler?
by khelenek
I'm curious if there are any hooks into the handling of runtime exceptions that propagate up through an EJB. The default behavior is to rollback a transaction and log the error. What I would like to be able to do is add my own custom logging here to add additional information on errors.
Let me back up and present the problem. Sometimes I get a hibernate runtime exception, which logs a stacktrace showing a series of "caused by's", until finally reaching something like this:
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into some_table... was aborted. Call getNextException to see the cause.
|
I would really like to get that getNextException() part logged as it is usually the most useful part of the exception. And i want to do it in a "global" sort of way without catching, logging, and rethrowing on every ejb method i have.
Thought also about making my own log4j appender but I'm not sure if that approach would work. Any other ideas or suggestions?
Thanks!
Kris
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095276#4095276
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095276
18Â years, 9Â months
[Persistence, JBoss/CMP, Hibernate, Database] - Ejb3Configuration => creating em and emf
by olvin
Hello,
I don't want to use anymore the persistence.xml file because the use of jar-file doesn't work (with relative path) if I have the entities on another jar-file in the same ear.
So I'm trying to create my own entityManagerFactory and entityManager to inject them into JNDI.
So the code is above.
But I have still this warning and no SQL Query works ! :
"WARN [AbstractEntityManagerImpl] Calling joinTransaction() on a non JTA EntityManager"
So, how can I force the transaction-type to JTA ??? Or another solution ?
Thanks,
Olv
| public boolean addEMToJNDI(String datasourceName)
| {
| try
| {
| //DataSource ds = (DataSource) JndiContext.lookup(datasourceName);
| Ejb3Configuration ejbconf = new Ejb3Configuration();
| //ejbconf.setDataSource(ds);
| ejbconf.setProperty("hibernate.session_factory_name", "persistence.units:ear=sts-sal.ear,unitName=PU-SQLBase-SAL57094");
| ejbconf.setProperty("hibernate.connection.datasource", datasourceName);
| ejbconf.setProperty("hibernate.connection.driver_class", "jdbc.gupta.sqlbase.SqlbaseDriver");
| ejbconf.setProperty("hibernate.transaction.factory_class", "org.hibernate.ejb.transaction.JoinableCMTTransactionFactory");
| ejbconf.setProperty("hibernate.transaction.manager_lookup_class", "org.hibernate.transaction.JBossTransactionManagerLookup");
| ejbconf.setProperty("hibernate.query.jpaql_strict_compliance", "true");
| ejbconf.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider");
| ejbconf.setProperty("hibernate.dialect", "stesud.hibernate.dialect.SQLBaseDialect");
| ejbconf.setProperty("hibernate.show_sql", "false");
| ejbconf.setProperty("hibernate.hbm2ddl.auto", "none");
| //ejbconf.setProperty("hibernate.ejb.naming_strategy", "com.fcl.greenfield.naming.FCLNamingStrategy");
| // Find all our persistent classes from ".jar"
| JarVisitor.Filter[] filters = new JarVisitor.Filter[2];
| filters[0] = new JarVisitor.PackageFilter(false, null)
| {
|
| public boolean accept(String javaElementName)
| {
| return true;
| }
| };
| filters[1] = new JarVisitor.ClassFilter(false, new Class[]{Entity.class, MappedSuperclass.class, Embeddable.class})
| {
|
| public boolean accept(String javaElementName)
| {
| return true;
| }
| };
|
| // Add all persistent classes to EJB3 config
| JarVisitor j = JarVisitor.getVisitor(Thread.currentThread().getContextClassLoader().getResource("sts-sal-common.jar"), filters);
| @SuppressWarnings(value = "unchecked")
| Set<JarVisitor.Entry>[] entries = (Set<JarVisitor.Entry>[]) j.getMatchingEntries();
| List<String> classes = new ArrayList<String>();
| for (int i = 0; i < entries.length; i++)
| {
| for (JarVisitor.Entry c : entries)
| {
| CalcLogger.getLogger().info("Found entity " + c.getName());
| ejbconf.addAnnotatedClass(Class.forName(c.getName()));
| }
| }
| CalcLogger.getLogger().debug("Building SessionFactory => em");
| EntityManagerFactory emf = ejbconf.buildEntityManagerFactory();
| ManagedEntityManagerFactory memf = new ManagedEntityManagerFactory(emf, "test");
| InjectedEntityManagerFactory iemf = new InjectedEntityManagerFactory(memf);
| EntityManager em = iemf.createEntityManager();
| CalcLogger.getLogger().debug("Adding EntityManagers and EntityManagerFactories to JNDI");
| JndiContext.addToJndi(GlobalConstants.PU_FACTORY_HEAD_JNDI_NAME.concat("/").concat(datasourceName.substring(datasourceName.length() - 8)), iemf);
| JndiContext.addToJndi(GlobalConstants.PU_HEAD_JNDI_NAME.concat("/").concat(datasourceName.substring(datasourceName.length() - 8)), em);
| CalcLogger.getLogger().info("EntityManagers and EntityManagerFactories added to JNDI");
| return true;
| }
| catch (ClassNotFoundException ex)
| {
| CalcLogger.getLogger().log(TraceLevel.ERROR, null, ex);
| return false;
| }
| catch (IOException ex)
| {
| CalcLogger.getLogger().log(TraceLevel.ERROR, null, ex);
| return false;
| }
| catch (Exception ex)
| {
| CalcLogger.getLogger().log(TraceLevel.ERROR, null, ex);
| return false;
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095273#4095273
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095273
18Â years, 9Â months
[JBoss jBPM] - How to test a deployed process?
by ZazzaZ
Hi all,
I realized a project, I succssfully deployed it.
I don't know how to write a client to test if the process I deployed works fine.
I tried by modify the ones I find with jboss examples but I got client-side errors. The error is
|
| [junit] 16:22:22,943 WARN JSR109ClientMetaDataBuilder : Cannot obtain the SEI mapping for: {http://esempio/jaws}Login
| [junit] 16:22:22,977 ERROR ServiceObjectFactory : Cannot create service
| [junit] org.jboss.ws.WSException: Cannot obtain java type mapping for: {http://esempio/jaws}logOn
| [junit] at org.jboss.ws.deployment.JSR109MetaDataBuilder.buildParameterMetaDataRpc(JSR109MetaDataBuilder.java:247)
| [junit] at org.jboss.ws.deployment.JSR109MetaDataBuilder.setupOperationsFromWSDL(JSR109MetaDataBuilder.java:196)
| [junit] at org.jboss.ws.deployment.JSR109ClientMetaDataBuilder.buildMetaDataInternal(JSR109ClientMetaDataBuilder.java:208)
| [junit] at org.jboss.ws.deployment.JSR109ClientMetaDataBuilder.buildMetaData(JSR109ClientMetaDataBuilder.java:126)
| [junit] at org.jboss.ws.jaxrpc.ServiceImpl.<init>(ServiceImpl.java:112)
| [junit] at org.jboss.ws.jaxrpc.ServiceObjectFactory.getObjectInstance(ServiceObjectFactory.java:181)
| [junit] at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
| [junit] at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1125)
| [junit] at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1142)
| [junit] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:705)
| [junit] at org.jboss.naming.client.java.javaURLContextFactory$EncContextProxy.invoke(javaURLContextFactory.java:135)
| [junit] at $Proxy1.lookup(Unknown Source)
| [junit] at javax.naming.InitialContext.lookup(InitialContext.java:351)
| [junit] at org.jbpm.bpel.tutorial.atm.AtmFrontEndTest.setUp(AtmFrontEndTest.java:53)
| [junit] at junit.framework.TestCase.runBare(TestCase.java:125)
| [junit] at junit.framework.TestResult$1.protect(TestResult.java:106)
| [junit] at junit.framework.TestResult.runProtected(TestResult.java:124)
| [junit] at junit.framework.TestResult.run(TestResult.java:109)
| [junit] at junit.framework.TestCase.run(TestCase.java:118)
| [junit] at junit.framework.TestSuite.runTest(TestSuite.java:208)
| [junit] at junit.framework.TestSuite.run(TestSuite.java:203)
| [junit] at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22)
| [junit] at junit.extensions.TestSetup$1.protect(TestSetup.java:19)
| [junit] at junit.framework.TestResult.runProtected(TestResult.java:124)
| [junit] at junit.extensions.TestSetup.run(TestSetup.java:23)
| [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:297)
| [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:672)
| [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:567)
|
|
Any help to this is accepted. Bye
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095269#4095269
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095269
18Â years, 9Â months