Re: problem with EJB-CMR access

"simon.robins" <[email protected]>
Newsgroups gmane.comp.java.tapestry.devel
Message-ID <[email protected]>
> I use EJB's for persistence (CMP 2.0 with CMR). I use the Foreach 
> component
> in Tapestry to loop over a CMR collection. This seems to be working ok.
>
> Page A
>    foreach ObjectType in CMR-collection
>        viewObjectType
>
> - viewObjectType is a self-made jwc that will access an relation in the
> ObjectType-instance. E.g: objectType.getInstances().size(). 
> getInstances()
> returns a CMR-collection.
>
> This generates an exception - "A CMR collection may only be used 
> within the
> transction in which it was created". I'm sure this is due to some
> threading-problem I don't fully understand.
>
> Can anyone shed some light on what I'm doing wrong?

You need to create a copy of the collection before you iterate through 
it. You can't access objects in a collection outside of the transaction 
you obtained the collection within. You know that you are only going to 
read them but the EJB container doesn't. There is some good 
documentation on Sun's web site that explains this.

Regards,

Simon



-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing 
your web site with SSL, click here to get a FREE TRIAL of a Thawte 
Server Certificate: http://www.gothawte.com/rd524.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.