Bugs item #840449, was opened at 2003-11-12 02:52
Message generated for change (Comment added) made by adrianprice
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=840449&group_id=22866

Category: JBossCMP
Group: v3.2
Status: Closed
Resolution: Rejected
Priority: 5
Submitted By: Adrian Price (adrianprice)
Assigned to: Alexey Loubyansky (loubyansky)
Summary: Exceptions from CMR iterator of NotSupported RO bean

Initial Comment:
Read-Only entity beans are typically deployed with a 
transactional attribute of NotSupported, because there 
is no intention to update the entity, and one wishes to 
leverage the container's caching capabilities across 
multiple transactions.  One does not wish the RO entity 
to be enlisted in a transaction, because this would 
negative impact performance by dramatically increasing 
the size of the cache required to support a given TPS 
throughput.  The same applies when an RO entity has a 
1:n or m:n relationship with other RO beans.  

According to the EJB2.0 Specification 17.6.2.1:

If a client calls with a transaction context, the 
container suspends the association of the transaction 
context with the current thread before invoking the 
enterprise bean�s business method. The container
resumes the suspended association when the business 
method has completed. The suspended transaction
context of the client is not passed to the resource 
managers or other enterprise Bean objects that are
invoked from the business method.

If the business method invokes other enterprise beans, 
the Container passes no transaction context with
the invocation.

However, according to the EJB2.0 Specification 10.3.8:

� It is the responsibility of the Container to throw the 
java.lang.IllegalStateException if an attempt is made to 
use a java.util.Iterator for a container-managed 
collection in a transaction context other than that in 
which the iterator was obtained.

It would seem that JBoss interprets this provision too 
literally, and throws an IllegalStateException even when 
a CMR collection of RO entities is obtained from within 
this same 'transaction suspended' state.  __This 
behaviour completely defeats the purpose of RO 
entities__.

For example, if we have two RO entities A and B, both 
deployed as txn NotSupported, and A has a 1:n 
parent:child relationship with B, the following code 
currently will not work:

public abstract class A implements EntityBean {
    // ejb*() etc...

    // Multi-valued CMR field.
    public abstract Collection getBCmr();
    public abstract void setBCmr(Collection bs);

    public BVO[] getBVO() {
        Collection bs = getBCmr();
        BVO[] bvo = new BVO[bs.size()];
        int i = 0;
        // Next line throws IllegalStateException!!!
        for (Iterator j = bs.iterator(); j.hasNext(); i++) {
            B b = (B)j.next();
            bvo[i] = b.getVO();
        }
        return bvo;
    }
}

BTW, the above code works fine on WebLogic.

----------------------------------------------------------------------

>Comment By: Adrian Price (adrianprice)
Date: 2003-11-13 20:27

Message:
Logged In: YES 
user_id=580837

In my example, the CMR collection was NOT being accessed 
from outside of the transactional context in which it was 
created; it was being used within the same NotSupported 
context.

Aside from the provisions of 17.4.1, I'm having some trouble 
following your logic (sorry).  Sure, NotSupported is now 
optional and non-portable, but so is the concept of read-only 
beans, but JBoss does purport to support that.

Here are a couple of important and inescapable points, borne 
of long personal experience with the read-mostly pattern:

1.) In order to make the read-mostly pattern useful to an 
application, an app. server really does need to support 
NotSupported for RO entities, because otherwise

EITHER:

A.) under txn Required or Mandatory the RO entities will be 
enlisted in an existing transaction until it commits, thus 
preventing that RO bean from being re-used in another 
concurrent transaction and forcing serialization on that 
bean.  Even if one uses a non-standard locking option 
like 'instance per transaction' to permit multiple copies of the 
entity to coexist in different transactions, that still has a 
profound impact on the size of the cache required to support 
a given transactional rate and concurrent user community, 
especially where multi-valued finders or CMR collections are 
involved.  The cache size necessary to support a given 
community of concurrent users becomes equals to the 
product nusers x nbeans-per-txn, compared to a mere 
nbeans for the NotSupported model.

OR

B.) Under txn RequiresNew, the container is obliged to start 
and commit a new transaction on every call to a business 
method on the RO bean, which is likely to have a negative 
performance impact unless the TXN_BEGIN can be deferred 
until the first transactional resource is enlisted (as would be 
the case if the bean was not already in the cache).  Also, 
under the 10.3.8 rule, you'd never be able to reference a CMR 
collection from such a bean if its CMR getter was exposed as 
a business method.  It is unclear to me what happens under 
JBoss if the CMR field is not exposed as a business method - 
does it still behave as RequiresNew even when called from 
within one of the business methods of the RO bean?

Given your position that JBoss is exhibiting spec.-compliant 
behaviour, which transactional attribute would you 
recommend for use with RO beans, and what is your response 
to the concerns I have described above?

Thanks.

----------------------------------------------------------------------

Comment By: Alexey Loubyansky (loubyansky)
Date: 2003-11-12 11:15

Message:
Logged In: YES 
user_id=543482

17.4.1 Transaction attributes
...For entity beans that use EJB 2.0 container-managed
persistence, only the Required,
RequiresNew, or Mandatory transaction attributes should be
used for the methods defined in the
bean�s component interface and all the direct and indirect
superinterfaces of the component interface,
excluding the getEJBHome, getEJBLocalHome, getHandle,
getPrimaryKey, and isIdentical
methods; and for the methods defined in the bean�s home
interface and all the direct and
indirect superinterfaces of the home interface, excluding
the getEJBMetaData and getHomeHandle
methods specific to the remote home interface. Containers
may optionally support the use of the
NotSupported, Supports, and Never transaction attributes for
the methods of entity beans with
container-managed persistence. However, entity beans with
container-managed persistence that use
these transaction attributes will not be portable.
Containers may optionally support the use of the
NotSupported, Supports, and Never
transaction attributes for the methods of entity beans with
container-managed persistence
because the use of these transaction modes may be needed to
make use of container-managed
persistence with non-transactional data stores. In general,
however, the Application Assembler
should avoid use of the NotSupported, Supports, and Never
transaction attributes for
the methods of entity beans with container-managed
persistence because it may lead to inconsistent
results or to the inconsistent and/or to the partial
updating of persistent state and relationships
in the event of concurrent use...

read-only (jboss.xml) entity beans are not associated with
transactions and are not invalidated and thrown out of the
cache when the tx commits. But CMR collections are tied to
the tx in which they were created. And when the tx commits,
the collection is invalidated. It is specification compliant
behaviour.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=840449&group_id=22866


-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to