ejb 3.0 - EJB3.0 transaction fail inside a method in successive transaction taking place -


I am processing three transactions within the same method in the stateless container managed bin. I want to continue three transactions, while one throws an exception, the other two should complete their respective deals, the error is that if the first or any other one is throwing exception, please implement some two useful suggestions.

  Public zero allocateSubjectToStudent throws exceptions (SubjectAllocatedToStudentDto DTO) {logger.info ("allocateSubjectToStudent method entry:"); & Lt; Subject & gt; CoreList = dto.getCoreList (); Iterator & LT; Subject & gt; Iterator = coreList.iterator (); While (iterator.hasNext ()) {logger.info ("when inside:"); Topics based on Confirmation Bo = new topic unapproved proofer (); Bo.setBacthId (dto.getBacthId ()); Bo.setSemester (dto.getSemester ()); Bo.setStudentId (dto.getStudentId ()); Subject subject = iterator.next (); Bo.setSubjectName (subject.getSubjectName ()); Bo.setSubjectType (subject.getAbatible ()); Try {Manager.persist (BO); } Hold (javax.preistence.PersistenceException e) {throwable t = e.getCause (); While ((t! = Null) & amp; amp; (t exampleof org.hibernate.exception.ConstraintViolationException) {t = t.getCause (); } // while (if T installation org. Hibernate.exception.ConstraintViolationException) {new exception throwing ("core topic already assigned to the student"); } // end of if} // end of capture // // end of the list & lt; Subject & gt; Departmentallist = dto.getDepartmentList (); Iterator & LT; Subject & gt; Iterator1 = departmentallist.iterator (); While (iterator1.hasNext ()) {logger.info ("unless:"); Topics based on Confirmation Bo = new topic unapproved proofer (); Bo.setBacthId (dto.getBacthId ()); Bo.setSemester (dto.getSemester ()); Bo.setStudentId (dto.getStudentId ()); Subject subject = iterator1.next (); Bo.setSubjectName (subject.getSubjectName ()); Bo.setSubjectType (subject.getAbatible ()); Try {Manager.persist (BO); } Hold (javax.preistence.PersistenceException e) {throwable t = e.getCause (); While ((t! = Null) & amp; amp; (t exampleof org.hibernate.exception.ConstraintViolationException) {t = t.getCause (); } // while (if T installation org. Hibernate.exception.ConstraintViolationException) (throwing new exception ("Inter departmental topic has already been assigned to the student");} // end of if} // capture end // // End of the list  electiveList = dto.getElectiveList (); Iterator & lt; subject & gt; iterator2 = electiveList.iterator (); while (iterator2.hasNext ()) {logger.info (" When: "); Topics based on the committed labeled bo = new topic unapproved proxy (); bo.setBacthId (dto.getBacthId ()); bo.setSemester (dto.getSemester ()); bo.setStudentId (dto.getStudentId ()); subject subject = Iterator2.next (); bo.setSubjectName (Sub.getSubjectN Try amo (); bo.setSubjectType (subject.getAbitute ()); {Manager.persist (BO);} hold (javax.preistence.PersistenceException e) {throwable t = e.getCause (); while (( T! = Null) & amp; amp; (T exampleof org.hibernate.exception.ConstraintViolationException) {t = t.getCause ();} // While (if T installation org.Hibernate.exception.ConstraintViolationException) {new Exception throw ("elective subject allocated to the student in advance"); } // end of if} // catch of end} // end of logger.info ("allocateSubjectToStudent method exit:"); } // the end of the method    

please create three different methods with all TranscationAttributeType REQUIRES_NEW Code snippet for EJB 3 bean below

  public zero doYourWork () {a (); B (); C(); } @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) Public Zero A () {Try {Do Here First Transaction} What Catch (Exception E) {}} @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) Public Zero B () {Try {// here Second transaction} hold (exception e) {}} @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) Public ZeroC () {try {// hold here (exception e) third transaction} {}}    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -