Hi,

A normal exception doesn't automatically
rollback the transaction. 
Only Errors, RuntimeExceptions and RemoteExceptions are handled by the
server.

You request a rollback using the EJB context.

SessionContext ctx;

public void setSessionContext(SessionContext ctx)
{
   this.ctx = ctx;
}

try
{
...
}
catch (ServiceLocatorException sle)
{
logger.fatal("importArchive() failed", sle);
ctx.setRollbackOnly(); // !!!!!! HERE !!!!!!
throw new TransferException("Transfer::importArchive() failed with
ServiceLocatorException", sle);
}

xxxxxxxxxxxxxxxxxxxxxxxx 
Adrian Brock
Director of Support
Back Office
JBoss Group, LLC 
xxxxxxxxxxxxxxxxxxxxxxxx 
 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Rafal Kedziorski
> Sent: 30 May 2003 10:43
> To: [EMAIL PROTECTED]
> Subject: [JBoss-user] transaction dosn't roll back ...
> 
> 
> Hi,
> 
> we have some problem with TransactionRollBack in our application.
> 
> We have TransferFacade session bean which will be called from 
> a servlet:
> 
> try {
>     Long ownUserID = getUserId();
>     Long mandantID = getMandantId();
> 
>     projectMD = transferFacadeHome.create().importArchive(ownUserID, 
> mandantID, importNode);
> }
> catch (TransferException te) {
>    logger.fatal("run() failed", te);
>    setStatusID(XMLErrorIDs.STATUS_ERROR);
> 
>    if (te.getErrorCode().equals(XMLErrorIDs.UNDEFINED_ERROR)) {
>      setErrorID(XMLErrorIDs.IMPORT_ARCHIVE_FAILED);
>    }
>    else {
>      setErrorID(te.getErrorCode());
>    }
> 
>    return;
> }
> 
> This session bean should import an zip archive with some 
> media files. All 
> meta data informations are stored in xml files which are 
> stored in the zip 
> archive.
> 
> And here is the part oth the code from our TransferFacade 
> session bean:
> 
> public ProjectMetaData importArchive(Long caller_user_id, 
> Long mandant_id, 
> XMLNode xmlNode)
>    throws TransferException {
>    ProjectMetaData projectMetaData = null;
> 
>    try {
>      MediaFacadeLocalHome mediaFacadeHome = (MediaFacadeLocalHome) 
> serviceLocator.getLocalHome(JNDINamesMedia.MEDIA_FACADE_SSLSB);
>      ProjectFacadeLocalHome projectFacadeHome = 
> (ProjectFacadeLocalHome) 
> serviceLocator.getLocalHome(JNDINamesProject.PROJECT_FACADE_SSLSB);
> 
>      ProjectFacadeLocal projectFacadeLocal = 
> projectFacadeHome.create();
>      MediaFacadeLocal mediaFacadeLocal = mediaFacadeHome.create();
> 
>      // create new project
>      projectMetaData = 
> projectFacadeLocal.createProject(caller_user_id, new 
> ProjectMetaData(null, mandant_id, projectName, null, 
> projectDescription));
>      Long project_id = projectMetaData.getProject_id();
> 
>      logger.info("importArchive() created project=" + project_id);
> 
>      // lock project
>      if (projectFacadeLocal.lockProject(caller_user_id, project_id)) {
>        // read single media and create it
>        for (int m = 0; m < countOfMedia; m++) {
>          media = mediaFacadeLocal.createMedia(caller_user_id, media, 
> mediaType, CREATE_MESSAGE);
> 
>          ...
> 
>          for (int mf = 0; mf < mediaFilesInfo.size(); mf++) {
>              ...
> 
>              billMD = 
> mediaFacadeLocal.addBilling(caller_user_id, billMD, 
> mediaFileCountry, mediaFileCurrency);
> 
>              ...
>          }
>          catch (ServiceLocatorException sle) {
>              logger.fatal("importArchive() failed", sle);
>              throw new 
> TransferException("Transfer::importArchive() failed 
> with ServiceLocatorException", sle);
>          }
>          catch (ParameterException pe) {
>              logger.fatal("importArchive() failed", pe);
>              throw new 
> TransferException("Transfer::importArchive() failed 
> with ParameterException", pe);
>          }
>          catch (PermissionException pe) {
>              logger.fatal("importArchive() failed", pe);
>              throw new 
> TransferException("Transfer::importArchive() failed 
> with PermissionException", pe);
>          }
>          catch (CreateException ce) {
>              logger.fatal("importArchive() failed", ce);
>              throw new 
> TransferException("Transfer::importArchive() failed 
> with CreateException", ce);
>          }
>          catch (ProjectException pe) {
>              logger.fatal("importArchive() failed", pe);
>              throw new 
> TransferException("Transfer::importArchive() failed 
> with ProjectException", pe);
>          }
> 
>          if (projectMetaData == null) {
>              logger.fatal("importArchive() failed because 
> ProjectMetaData 
> null");
>              throw new 
> TransferException("Transfer::importArchive() failed 
> because ProjectMetaData null");
>          }
> 
>          return projectMetaData;
>      }
> }
> 
> At first we are creating a new project. After that we import 
> some files 
> which will be at least added to the new project. We are 
> calling MediaFacade 
> session bean, which checks parameters and call other session 
> bean, which 
> implement our business logic (TransferFacade can communitate 
> with other 
> modules only thru a facade session beans). And the last 
> session bean is 
> calling entity beans. For each file we are creating some meta 
> data like 
> price, language, name, description, ...
> 
> i.e. if
> 
> billMD = mediaFacadeLocal.addBilling(caller_user_id, billMD, 
> mediaFileCountry, mediaFileCurrency);
> 
> failed with an ParameterException, which we intercept in the 
> code above, 
> while we want throw TransferException to our servlet and rollback our 
> dbtransaction, than all the written data to the db is not 
> rolled back. And 
> we are all the time in the same transaction.
> 
> Is the an JBoss or our problem?
> 
> We tested this with JBoss 3.2.1 and 3.2.2beta from cvs (one 
> week old). We 
> use PostgreSQL 7.3.2.
> 
> 
> Best Regards,
> Rafal
> 
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: eBay
> Get office equipment for less on eBay!
> http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user
> 





-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to