Skip to content

Instantly share code, notes, and snippets.

@hussachai
Created October 27, 2013 07:11
Show Gist options
  • Save hussachai/7178721 to your computer and use it in GitHub Desktop.
Save hussachai/7178721 to your computer and use it in GitHub Desktop.
@SkipInjectionError
public class BugzookyBootstrap implements StarsBootstrap {
@PersistenceContext
private EntityManager em;
@Resource
private UserTransaction userTx;
@Override
public void execute(ServletContext servletContext) throws Exception {
if(ServiceProvider.isEjb(servletContext)){
userTx.begin();
}else{
if(!em.getTransaction().isActive())
em.getTransaction().begin();
}
try{
generateTestData(servletContext);
if(ServiceProvider.isEjb(servletContext)){
userTx.commit();
}else{
em.getTransaction().commit();
}
}catch(Exception e){
if(ServiceProvider.isEjb(servletContext)){
userTx.rollback();
}else{
em.getTransaction().rollback();
}
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment