[JBoss-user] [Persistence CMP/JBoss] - Re: No rollback of inserted data?
Thanks, dannyyates. The book is surprisingly comprehensive :) View the original post : http://www.jboss.org/index.html?module=bbop=viewtopicp=3839055#3839055 Reply to the post : http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3839055 --- This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [Persistence CMP/JBoss] - Re: No rollback of inserted data?
Thanks all for your replies. After I read the EJB 2.0 specification, I can understand why the transaction is not rollbacked automatically (If everything else failed, read the documentation... ;)). I am nevertheless somewhat unsure how I should handle exceptions. I surrounded critical sections with try/catch blocks to catch all known Exceptions, including RuntimeExceptions (in the rare case of some bug into the code) to ensure a rollback in case of an error. My code works now and all transaction are rollbacked regardless which exceptions the EJB will throw. Is this the right way to handle exceptions? View the original post : http://www.jboss.org/index.html?module=bbop=viewtopicp=3838966#3838966 Reply to the post : http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3838966 --- This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [Persistence CMP/JBoss] - Re: No rollback of inserted data?
Java broadly divides exceptions into two types: checked and unchecked. Unchecked exceptions derive from RuntimeException or Error. Everything else is a checked exception. Checked exceptions are the ones that the compiler forces you to either catch or else declare with a throws clause in your method declaration. The EJB spec talks about application and system exceptions. Broadly, EJB system exceptions are the same as Java unchecked exceptions, with the addition of anything deriving from java.rmi.RemoteException. That is, EJB system exceptions are RuntimeException, Error and RemoteException and their descendants. RuntimeException and Error should never be generated by your code - they typically come from the JVM in response to critical, non-recoverable system problems (like, out of memory, etc.) RemoteException should also never be generated by your code - they are generated by the RMI runtime in response to comms (network) related problems. Since you should never be generating any of these EJB system exceptions, (and most of them are unchecked anyway) it is unreasonable for the container to expect you to deal with them. Therefore, if any of these make their way out of your bean method, the container will catch them and roll back your transaction for you. However, any EJB application exceptions (everything other than system exceptions) are checked. Therefore, the compiler will force you to catch them or explicitly rethrow them. Since you are forced into doing this, the container assumes that you have the power to decide whether to roll back the transaction or not. If you propogate these exceptions back up to the container, it will send them across the wire and they will appear on your client. This is good. However, the container doesn't know if the client is capable of retrying the operation, etc. Therefore it doesn't automatically roll back the transaction. So... the compiler is your friend. If you always catch the exceptions it tells you to catch, then you will be in command of all EJB application exceptions. You can then decide what the correct action is. In my experience, the correct action is typically to roll back the transaction and then rethrow the exception so that the client is aware of it. For a more thorough treatment of this subject, check out Monson-Haefel, Enterprise Java Beans (I have the 3rd edition which covers EJB2.0) published by O'Reilly. Chapter 14 deals with transactions, and the section 'Exceptions and Transactions' deals with exactly that, and very thoroughly. I highly recommend the table on pp439-441 (of the 3rd edition). View the original post : http://www.jboss.org/index.html?module=bbop=viewtopicp=3838969#3838969 Reply to the post : http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3838969 --- This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [Persistence CMP/JBoss] - Re: No rollback of inserted data?
Oh, and it also depends on whether your database supports transactions. I understand that certain configuration of MySQL, for example, don't. Not sure about Hypersonic. View the original post : http://www.jboss.org/index.html?module=bbop=viewtopicp=3838675#3838675 Reply to the post : http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3838675 --- This SF.Net email is sponsored by the new InstallShield X. From Windows to Linux, servers to mobile, InstallShield X is the one installation-authoring solution that does it all. Learn more and evaluate today! http://www.installshield.com/Dev2Dev/0504 ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [Persistence CMP/JBoss] - Re: No rollback of inserted data?
If you read the spec you will see that rollback on on only some exceptions make sense. One of the most important things to understand in J2EE development is transactions. If you want to force rollback you can always play with the setRollbackOnly() method. /G View the original post : http://www.jboss.org/index.html?module=bbop=viewtopicp=3838718#3838718 Reply to the post : http://www.jboss.org/index.html?module=bbop=postingmode=replyp=3838718 --- This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user