[EJB/JBoss] - 3 questions on transactions - misunderstanding or bug
by X490812
I will give the pertinent code for 3 use cases and describe the outcomes. The outcomes dont make sense for my understanding of EJB3.0.
the function batchRemoveEndedProcesses does a simple delete from an oracle db. All this is in a SLSB
| @TransactionAttribute(javax.ejb.TransactionAttributeType.REQUIRED)
| public void cleanupEndedProcesses(String processId)
| .
| .
| while (pidVec.size() > 1075)
| {
| endNdx = pidVec.size() > BATCHSIZE? BATCHSIZE:pidVec.size();
| tmpList = new ArrayList<String>(pidVec.subList(0, endNdx));
| batchRemoveEndedProcesses(tmpList, jbpmDAO);
| cnt += endNdx;
| pidVec.removeAll(tmpList);
| }
| .
| .
| @TransactionAttribute(javax.ejb.TransactionAttributeType.REQUIRES_NEW)
| private void batchRemoveEndedProcesses(List<String> pidVec, JbpmDAO jbpmDAO)
| {
| try {
| jbpmDAO.removeEndedProcesses(pidVec);
| }
| catch (Exception e) {
| throw new WorkflowException(e);
| }
| }
|
|
first call to removeEndedProcesses succeeds, second call succeeds
start: 1080 rows to be deleted
end1 removeEndedProcesses : 1080 rows to be deleted
end2 removeEndedProcesses : 1080 rows to be deleted
end: 1070 - 10 rows deleted
ISSUE: WHY DOES THE REQUIRES_NEW FUNCTION NOT COMMIT
i UNDERSTOOD THAT WHEN YOU HAVE REUQIRES_NEW, THE FUNCTION WILL COMMIT ITS TRANSACTION
--------------------------------------------------------------------------------
| @TransactionAttribute(javax.ejb.TransactionAttributeType.NEVER)
| public void cleanupEndedProcesses(String processId)
| .
| .
| while (pidVec.size() > 1075)
| {
| endNdx = pidVec.size() > BATCHSIZE? BATCHSIZE:pidVec.size();
| tmpList = new ArrayList<String>(pidVec.subList(0, endNdx));
| batchRemoveEndedProcesses(tmpList, jbpmDAO);
| cnt += endNdx;
| pidVec.removeAll(tmpList);
| }
| .
| .
| @TransactionAttribute(javax.ejb.TransactionAttributeType.REQUIRES_NEW)
| private void batchRemoveEndedProcesses(List<String> pidVec, JbpmDAO jbpmDAO)
| {
| try {
| jbpmDAO.removeEndedProcesses(pidVec);
| context.setRollbackOnly();
| }
| catch (Exception e) {
| throw new WorkflowException(e);
| }
| }
|
|
first call to removeEndedProcesses succeeds. Whenrollback called and throws exception
Caused by: java.lang.IllegalStateException: setRollbackOnly() not allowed without a transaction.
start: 1080
end1 removeEndedProcesses : 1080
end: 1080
ISSUE: Why does CODE act as if REQUIRES_NEW is not there?
--------------------------------------------------------------------------------
| @TransactionAttribute(javax.ejb.TransactionAttributeType.REQUIRED)
| public void cleanupEndedProcesses(String processId)
| .
| .
| while (pidVec.size() > 1075)
| {
| endNdx = pidVec.size() > BATCHSIZE? BATCHSIZE:pidVec.size();
| tmpList = new ArrayList<String>(pidVec.subList(0, endNdx));
| batchRemoveEndedProcesses(tmpList, jbpmDAO);
| cnt += endNdx;
| pidVec.removeAll(tmpList);
| }
| .
| .
| @TransactionAttribute(javax.ejb.TransactionAttributeType.REQUIRES_NEW)
| private void batchRemoveEndedProcesses(List<String> pidVec, JbpmDAO jbpmDAO)
| {
| try {
| jbpmDAO.removeEndedProcesses(pidVec);
| context.setRollbackOnly();
| }
| catch (Exception e) {
| throw new WorkflowException(e);
| }
| }
|
first call removeEndedProcesses succeeds (no commit) and then does rollback with no exception. Second call removeEndedProcesses throws esception when getting a connection:
Caused by: javax.resource.ResourceException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=ro-0029aits/47, BranchQual=, localId=47]
ISSUE: Why does rollback screw things up for the next run through the REQUIRES_NEW function?
---------------------------------------------------------------------------
The only way I could get above deletes to commit as I wanted (in batches) was if the loop above was in a javax.ejb.TransactionAttributeType.NEVER function; This should not be necessary(I thought).
In addition, for unit testing, I wanted to rollback via context.setRollbackOnly(), and I could not get that to work ;
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4073660#4073660
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4073660
18Â years, 11Â months
[Messaging, JMS & JBossMQ] - Re: connectionFactoryJndiName config property
by adamhmitchell
When you add the "@ResourceAdapter("foo.rar")" annotation to the MDB, are the JNDI bindings you created in the *-ds.xml file being used?
I'm trying to use Sun's MQ server (IMQ) in JBoss and I found that I could deploy the RAR from Sun IMQ and use the following annotations (without using a *-ds.xml datasource):
| @MessageDriven(mappedName = "jms/LoggingEventBean", activationConfig = {
| @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
| @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
| @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
| @ActivationConfigProperty(propertyName = "clientId", propertyValue = "LoggingEventBean"),
| @ActivationConfigProperty(propertyName = "destination", propertyValue = "elm_topics_LoggingEvent_default"),
| @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "LoggingEventBean")
| //@ActivationConfigProperty(propertyName = "UserName", propertyValue = "guest"),
| //@ActivationConfigProperty(propertyName = "Password", propertyValue = "guest")
| })
| @ResourceAdapter("imqjmsra.rar")
| public class LoggingEventBean implements MessageListener {
|
| ...
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4073651#4073651
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4073651
18Â years, 11Â months
[JBoss Seam] - How to display exception messages for fields
by ellenzhao
Here is the entity class:
| @Entity
| @Name("foo")
| @Table(name = "foo")
| public class Foo implements Serializable {
| ...
| @Column(name = "non_repeat_cycle", nullable = false)
| public Short getNonRepeatCycle() {
| return nonRepeatCycle;
| }
|
| public void setNonRepeatCycle(Short nonRepeatCycle)
| throws IllegalNonRepeatCycleException {
| boolean valid = true;
| if (nonRepeatCycle <= 0) {
| valid = false;
| throw new IllegalNonRepeatCycleException(nonRepeatCycle);
| }
| if (valid){
| this.nonRepeatCycle = nonRepeatCycle;
| }
| }
| ...
|
Client code in xhtml:
| <s:decorate template="layout/edit.xhtml">
| <ui:define name="label">Non-repeat cycle:</ui:define>
| <h:inputText
| value="#{fooManager.foo.nonRepeatCycle}" required="true" />
| <h:outputText value=" days" />
| </s:decorate>
|
|
The idea is that, this way the entity knows how to validate itself and I do not have to write a separate validator.
In fact it works very well, when I tested with the number "-3", there is error message displayed in red and the conversation hanged like expected (hanged but not killed, after I corrected the value, the conversation goes smoothly), and the view is also like expected....The only problem is, the error message looks like this:
| /foo-management.xhtml @58,31 value="#{fooManager.foo.nonRepeatCycle}": Error writing 'nonRepeatCycle' on type myproject.entity.Foo
|
My exception class looks like this:
| public class IllegalNonRepeatCycleException extends Exception {
| private static final String DEFAULT_MSG = "Non-repeat-cycle must be greater than zero!";
| @Logger
| private static Log log;
|
| public IllegalNonRepeatCycleException(){
| super(DEFAULT_MSG);
| }
|
| public IllegalNonRepeatCycleException(Short nonRepeatCycle) {
| super(DEFAULT_MSG + " " + nonRepeatCycle + " is illegal.");
| log.info("Exception generated!");
| }
|
| public String toString(){
| return this.getMessage();
| }
| }
|
It would be nice if the error message in the view can be the exception message. How to do this? Thanks in advance for any help!
Regards,
Ellen
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4073648#4073648
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4073648
18Â years, 11Â months