wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes CMP Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "CMP Exception Handling" Watch "CMP Exception Handling" New topic
Author

CMP Exception Handling

anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi Folks:

I am kind of confused abt what kind of exceptions can be thrown by container in various case.
I am using CMP, jboss 3.2.6 and all of my methods set/get for name,status are "Required" attributed. From POJO I am looking up bean ( for which I am using utility class which will convert Naming exception and all checked exceptions that can occur in look up to EJB Exception). So in POJO I am catching EJBException and converting that to APPLICATION SPECIFIC EXCEPTION(part of our standard),after bean lookup I am calling Finder method so I case of FinderException I am catching it and converting it to App specific exception(part of standard). Once I find the bean calling setters to set the fields and my bean is local to my POJO class. When I am setting bean fields I have various scenarios to handle, 1. If back end database is down what kind of exception container can throw and Is container do Database clean up, is there anyway for me to catch exception that can be thrown by container in this case 2. While looking up for record using Finder method what if data base is down is there any way that I can handle this scenario.
Since my bean is local my bean methods are not throwing RemoteExceptions. I am so concern about these since today morning server was up and running but database was done so when findbyprimarykey in POJO executed container is throwing FinderException with embedded SQLException for network adapter couldn't able to establish connection, so I want to catch it and throw App specific exception saying that Database is down. I want to make it so generic such that whenever database is DOWN at any point of time while executing methods on bean I should be able to say database is down.

Please let me know ASAP, your advice will make me to spin the wheel.

Thanks alot,
Anu
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Are you obtaining your Connection as late as possible? If so, then you will get SQLException if the DB is down.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi Roger Chung-Wee ,
Thanks alot for your reply, I am getting connection from pool before I call queries on database. I am getting SQL Exception:Io Exception:Network Adapter Couldn't establish connection, but it's wrapped inside JBoss Resource Exception and which is wrapped in FinderException if I DB is down at Finder method. I am thinking to get SQLException embedded in Finder Exception and see message, if it is Network Adapter Couldn't establish connection and if so I will throw DB down application exception. But my question I need to come up with generic utility class, which will see exception thrown from container and has to determine whether DB is down or not irrespective of point at which it occured(Find method/setter methods). When I call set methods on bean, before container call update on DB what kind of exception container throws if DB is down at that point. I browse on Net but I didn't get any useful links.

At this point I need your valuable sugggestions, please post any links that will be useful.

Thanks alot,
I will look forward to your reply.
Anu
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Try invoking getCause().getClass().getName() on the exception and see if it returns the object which is cause of the problem.
anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi Roger Chung-Wee ;

Within JBoss logging messages exception stack trace is

Caused by: org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory
)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:168)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:508)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:207)
at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:534)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:444)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:429)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:496)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:887)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:102)
... 124 more
Caused by: java.sql.SQLException: ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOsesskey(T4CTTIoauthenticate.java:239)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:295)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:344)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:148)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:545)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:158)
... 132 more


but when I do findByPrimaryKey on bean I was getting FinderException with the following message in Message

(org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: (java.sql.SQLException: ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory
); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory
)))

So if I say e.getCause() it's returning null since all info in Message, I don't why container is chaining Root SQL exception to it.

Do you have any idea?please let me know.
Thanks alot,
Anu
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

This is Oracle problem. Restart your oracle server.


Groovy
anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi Pradip,
Thanks alot for ur reply, we have a requirement to throw App Specific Exception to client when DB is down(Even DB instance is n't up). Along those line I need to catch above mentioned exception and see if DB down is causing the exception. But interesting thing JBoss 3.2.6 container including all exceptions(JBoss Resource Exception and SQLException) in message but seems like not chaning those. Is this what container supposed to do? or Am I missing something.

Is going through Exception message to determine DB down is proper way?

Please let me know.
Thanks alot,
Anu
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by anupa oru:
Hi Pradip,
Thanks alot for ur reply, we have a requirement to throw App Specific Exception to client when DB is down(Even DB instance is n't up). Along those line I need to catch above mentioned exception and see if DB down is causing the exception. But interesting thing JBoss 3.2.6 container including all exceptions(JBoss Resource Exception and SQLException) in message but seems like not chaning those. Is this what container supposed to do? or Am I missing something.

Is going through Exception message to determine DB down is proper way?

Please let me know.
Thanks alot,
Anu


What about the error code ? Try sqlException.getErrorCode(). This method is supposed to return vendor-specific exception code for this SQLException object./ sqlException.getNextException() returns the chained exception.
anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi Pradip:

I have 2 concerns.

1. JBoss 3.2.6 container is including all root exceptions (JBoss Resource Exception,SQLException) in message but not chaning those
2. regarding SQL error codes Oracle latest version is including "ORA-01034: Oracle not Available as error code" but previous version has something like "Io Exception: Network Adpater couldn't establish connection".Moreover I guess error code for SQLException is n't manadatory and I think they depend on backend database version also. But I would like to say DB is down even backend database (Oracle) version has been changed. So I was thinking of relying on JBoss Resource Exception which is caused by SQLException.

My concern is why container is including all exception is message but not chaining up those. Is this Ok?or Am I miss something. Right now I am checking in exception message (If exception chain isn't there)and checking for existence of JBossResourceException with "couldn't establish connection", if so saying DB is down. If given exception has exception chain checking for "same thing" in exception chain.

Please let me know Am I in right track.
Thanks alot,
Anu
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
What do you get when you invoke getNested()? Ascertain the type of object returned and invoke getCause() on the nested object. A cause can only be assigned once in the lifetime of the Throwable, and I suspect that it was done here.
anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi,
Do I need to call getNested() on exception thrown from container, I didn't get you can u please elaborate that. My question is though JBoss internal classes logging exception along with JBOSS RESOURCE EXCEPTION and SQLEXCEPTION in chain but when it comes to EJB Container it's including those in exception message. So Jboss internal classes log exception with Caused by:JBoss Reource Exception blah....blah with stack trace (has Cuased by SQLException: blah...).But when I catch that exception in POJO which calls bean,exception has "JBoss Reource Exception ","SQLException" in exception message not in the chain. Is this the way container supposed to throw or am I missing something. Right now to check database status I am checking exception message of container exception and looking for "Jboss Resource Exception" if so saying that DB is down. Is this proper way or am I missing something.

Thanks alot,
Anu
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

I have a question -
Are you using sqlException.getCause or sqlException.getNextException ?

anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi Pradip,

Now exception from container doesn't have sql exception in chain as

As you can see all exceptions that causes exception are included in exception message when container returns to bean, but JBOSS internal classes logging messages are

so as you can see exceptions are chained.

I am wondering why container is n't giving me chained exceptions, or am I need to do something to see chained exceptions. Since SQLException is root cause for this exception and included in message, I amn't calling any method on SQLException.

Thanks
Anu
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

I think you have to rely on ResourceException since it is not chaining SQLException.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CMP Exception Handling