-
1. Re: getting an errror when try to get cmr collection.Please
tpaulson Apr 29, 2003 11:53 AM (in response to hvyas27)I have discovered a satisfactory answer to the problem of CMR-based transaction errors in JSPs/Servlets.
I embedded a little bit of Java code into my JSP page to surround the CMR-based accesses with a transaction. I found out how to implement a transaction from a JBoss client in the QuickStart guide. Here is the relevant part of my JSP page:
<%@ page import="javax.naming.*,javax.transaction.UserTransaction" %>
IdDescriptionCost
<%
Context jndiContext = new InitialContext();
UserTransaction ut = (UserTransaction)jndiContext.lookup("UserTransaction");
ut.begin();
%>
<c:forEach var="buy" items="${indiv.buys}">
<c:out value="${buy.buyId}"/>
<c:out value="${buy.description}"/>
<c:out value="${buy.cost}"/>
</c:forEach>
<%
ut.commit();
%>
In this case, I am using JSTL tags to control the loop and to access each of the "Buy" EJBs that are returned by the JSTL-based expression "${indiv.buys}". This expression is mapped to a EJB CMR accessor call (indiv.getBuys()).
So, at the moment I have some messy looking Java code that surrounds the CMR-based stuff with a transaction. But, this can easily be converted into a special tag in my own tag library. I plan to implement a tag like:
<mine:user_transaction>
<!-- CMR accesses -->
</mine:user_transaction>
Information about Transactions in JBoss can be found in the QuickStart guide.
I think it would be good to add some CMR-based accesses to CrimePortalTest.java of the "JBoss 3.0 Template" code (http://prdownloads.sourceforge.net/jboss/JBoss.3.0TemplateAndExamples.zip).