[jboss-user] [JBoss Seam] - Re: @Asynchronous / Conversations / Transactions Best Practi

2007-06-29 Thread chane
Thanks Gavin for the reply.

I finally figured something out.  Working with new technology is always fun, 
even if it is a bit frustrating.  I'm very new to using EJB3 - in fact I 
switched to using it (from tomcat/hibernate) when seam was still in it's first 
releases (mainly cvs at that time) because I saw the power of the framework).  
But now I need to go back and learn some of the things the framework manages 
for me.

I ended up putting

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

on the class and method of the called method.  Then in the method I create a 
new EntityManager.  It's a little heavy handed but does the trick.  I thought I 
could reuse the em for each transaction call; but couldn't figure it out.  It 
works, just wondering if there was a better way.  I tried a couple of things 
with UserTransaction but just didn't get it to work.  Probably my fault.

Thanks again,
Chris


  | @Name(value=importSale)
  | @Stateful
  | @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
  | public class ImportSale implements IImport {
  |
  |private EntityManagerFactory emf = null;
  |private EntityManager em;
  |
  |private EntityManager txEntityManager(){
  |   return getEntityManagerFactory().createEntityManager();
  | }
  |
  |private EntityManagerFactory getEntityManagerFactory(){
  |   if(emf == null) {
  |  try {
  | return (EntityManagerFactory) 
Naming.getInitialContext().lookup(java:/customEntityManagerFactory);
  |  } catch(NamingException ne) {
  | throw new IllegalArgumentException(EntityManagerFactory not 
found, ne);
  |  }
  |   } else {
  |  return emf;
  |   }
  |}
  | 
  |@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
  |public void processXML(ParseFile parseFile, State state, Element record) 
{
  |   internalProcess(record);
  |}
  |
  |private void internalProcess(Element record){
  |   try {
  |  em = txEntityManager();
  |  Contexts.getMethodContext().set(em, em); //added since DAO 
method access the em via
  | 
//Contexts.lookupInAllStates(or
  |// whatever the 
method is called)
  |  if(processXML(record)){
  |  } else {
  | Transactions.setTransactionRollbackOnly();
  |  }
  |   } catch(Exception ex){
  |  try {
  | Transactions.setTransactionRollbackOnly();
  |  } catch(Exception e) {
  | throw new RuntimeException(Could not rollback erred record, 
e);
  |  }
  |   }
  |}
  |
  |/snip rest
  | }
  | 

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=4059235#4059235

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=4059235
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: @Asynchronous / Conversations / Transactions Best Practi

2007-06-29 Thread [EMAIL PROTECTED]
Why not just use @PersistenceContext?

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=4059280#4059280

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=4059280
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: @Asynchronous / Conversations / Transactions Best Practi

2007-06-29 Thread chane
Thanks - I'll give that a try.  I didn't try since once I figured out how to use

@In
EntityManager em

I didn't look at this piece again and I forgot about it.  Now that I've been 
through a more in depth learning process, I won't forget about this again 
(actually I probably never really learned it the first time).

Thanks for the pointer,
Chris

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=4059315#4059315

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=4059315
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: @Asynchronous / Conversations / Transactions Best Practi

2007-06-28 Thread [EMAIL PROTECTED]
1. You can use standard EJB3 mechanisms for transaction demarcation, which 
certainly lets you have multiple transactions.

2. An asynchronous method gets a a new temporary conversation context. It 
cannot access the conversation context from which it was spawned.

HTH

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=4058897#4058897

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=4058897
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user