Help coderanch get a
new server
by contributing to the fundraiser

Oliver Rensen

Ranch Hand
+ Follow
since Jul 23, 2004
Oliver likes ...
Eclipse IDE Firefox Browser Java
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Oliver Rensen

Hi ranchers,

I have a question regarding transactions in Session-Beans.

There is the following method in a Stateless Session-Bean:

The class DataAccessObject is a POJO.

The method bookProdOrders() uses JDBC for the database-access:

In the first SQL-statement I read all records where the booked-field is not set.

Then I do some business-logic.

At the end I make an SQL-update on the same table and set a value into the booked-field, so that this records will not be booked twice.

Is this approach transaction-safe?

What would happen when two or more users call the SLSB-method bookProdOrders() on the same time?
Would the two or more SLSB-method-calls on bookProdOrders() be handled sequentially from JBoss?

Does the TransactionAttributeType Required has an impact on the JDBC-calls?

Kind regards

Pedro & Jayr, many thanks for the quick answers and the clarification.

The article by Adam Bien is very interesting!
Hi ranchers,

is it recommended to annotate every SLSB-method that does not use entities or TXs with


Would this annotation increase the performance of the method call?

Kind regards

I have created my own proprietary solution. It's not nice, but it works.

13 years ago

is it possible to retrieve informations from the Java Control Panel within a Java-program ?

In my source-code I want to know which option is selected in the network settings from the Java Control Panel.

How can I detect programmatically whether direct connection is selected or not?

Kind regards
13 years ago

we use JPA 2 (EclipseLink) to do the following:

a) Insert a record into a table from our ERP-system.
b) Call an event for our ERP-system.
c) The ERP-system (not Java based) reads the record from a) after receiving the event.

a) and b) looks like the following:

Sometimes the problem occurs that the ERP-system cannot see the inserted record, because the ERP-event executes faster than the record was inserted with JPA.

Is it possible to guarantee after em.close() that the database is up to date?

Kind regards
After seven month of preparing I have passed SCBCD 5 with 95%.

The exam was difficult but fair.

I have read the following books:

EJB 3 in Action: A boring read and sometimes confusing. Not a good start for beginners. I don't like this book.

Pro EJB 3: The best book regarding JPA. Excellent and highly recommended.

Enterprise JavaBeans 3.0 from Bill Burke: Easy to read and easy to understand. I have learned a lot from this book.

JBoss in Action from Peter Johnson (a Javaranch-moderator): Amazing book, interesting to read and very competent & comprehensive. Invaluable!

JBoss AS 5 Development from Francesco Marchioni: A good survey through JBoss and the JBoss Tools for Eclipse. This book contains good informations for the practical work with JEE.

JBoss Tools 3 Developer's Guide from Anghel Leonard: Nice to read, but I have missed EJB- and JPA-tutorials.

Mikalai Zaikin Study Guide: Very professional compendium for the exam objectives.

Refering sometimes to the EJB specs.

JPA is not that easy and you cannot grasp the concepts only with one book. "Pro EJB 3", "Enterprise JavaBeans 3.0" and "JBoss in Action" are the best technical books I have read for a long time.

What's next? Learning SEAM.

JBoss rocks. Eclipse, too!

14 years ago
I used JBoss 5.1, too.
It's very robust and easy to handle.
Jaikiran, thank you for the help.
The following is an excerpt from the book "Pro EJB 3". I like this book very much, but the following example is one of the few things that I have problems to understand:

The book says:
"The ChangeCollisionException class is annotated with @ApplicationException, which is an EJB 3.0 containter annotation in the javax.ejb package to indicate to the container that the exception is not really a system-level exception but should be thrown back to the client as is. Normally, defining an application exception will cause the container to not roll back the transaction, but this is an EJB 3.0 container notion. The persistence provider that threw OptimisticLockException does not know about the special semantics of designated application exceptions and seeing a runtime exception will go ahead and mark the transaction for rollback."

And the spec says:
" An application exception does not automatically result in marking the transaction for rollback unless the
ApplicationException annotation is applied to the exception class and is specified with the
rollback element value true or the application-exception deployment descriptor element
for the exception specifies the rollback element as true."

In the above example the ApplicationException annotation has no rollback element set to true. I do not understand why "throw new ChangeCollisionException()" causes the transaction to roll back.

when a stateless session bean method throws a system-exception, the transaction will be rolled back. But when I catch the system-exception and rethrow an application-exception to the client, will the transaction still be rolled back?

Does this code lead to a rollback?

Kind regards
Thank you Jesper for your clarification.
In example a), there is created a new local count-variable on the stack for each iteration.
The GC must delete the count-variable from the stack after each iteration, and the GC must delete the ArticleCount-reference from the heap after each iteration.

In example b), there is created only one local count-variable on the stack, pointing always to a new ArticleCount-reference while iterating.
The GC must still delete the ArticleCount-reference from the heap after each iteration, but the GC must delete the count-variable from the stack only once: after the method completes.

This is my understanding, but it can be wrong.

What is better from the viewpoint of garbage collection?

a) Declare the iterator-variable within the loop:

b) Declare the iterate-variable before the loop:

I'm not sure whether these examples are equivalent or not.
Does example b) perform better than example a) ?