[EJB/JBoss] - how to turn on ejb transaction demarcation?
by kannattaa
hello!
i have jboss-4.2.3GA and example from jboss-seam-2.1.1.GA sources (seam-booking)
i want to save user in a transaction and then change his name in another transaction, so some changes were made in RegisterAction.java:
public void register()
| {
| if ( user.getPassword().equals(verify) )
| {
| List existing = em.createQuery("select u.username from User u where u.username=#{user.username}")
| .getResultList();
| if (existing.size()==0)
| {
| persistUser();
|
| user.setName(user.getName() + "1");
| persistUserWithException();
|
| facesMessages.add("Successfully registered as #{user.username}");
| registered = true;
| }
| else
| {
| facesMessages.addToControl("username", "Username #{user.username} already exists");
| }
| }
| else
| {
| facesMessages.addToControl("verify", "Re-enter your password");
| verify=null;
| }
| }
|
| @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
| private void persistUser() {
| em.persist(user);
| }
|
| @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
| private void persistUserWithException() {
| em.persist(user);
| throw new RuntimeException();
| }
this expects that user with original name will be persisted, but change of his name won't apply.
but this doesn't work. both operations will be rollbacked because they are in the same transaction.
what's wrong? please help me!
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4215051#4215051
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4215051
17 years, 2 months
[EJB 3.0] - Re: TIMER SERVICE EJB 3.0 - Need Help
by pramkum
Jai,
My Timer bean code is
|
| /**
| * Timer bean used to periodically search to see if any pager forward requests have been entered.
| *
| * @jboss.container-configuration name="Singleton oncall Standard Stateless SessionBean"
| *
| *
| */
|
|
|
| @Stateless(mappedName="ejb/OnCallTimerBean")
| @Remote(OnCallTimer.class)
| @Local(OnCallTimer.class)
| public class OnCallTimerBean implements OnCallTimer {
|
|
|
| /**
| * use for logging
| */
| Log log = LogFactory.getLog(this.getClass());
|
| /**
| * reference to the timer handle
| */
|
| private TimerHandle timerHandle = null;
|
| /**
| * Poll records after following interval.
| */
| private static int POLLING_TIME = 60000;
|
| /**
| * status flag to determine transaction state
| * set this flag to disable timer call
| */
| private static boolean processFlag = false;
|
|
| private OnCallService oncallService = null;
|
| @Resource
| private SessionContext sessionCtx;
| public void startTimer() {
|
| System.out.print ("Inside startTimer ");
| if (log.isInfoEnabled()) {
| log.info("startTimer Service ");
| }
|
| try {
| // Create timerService instance
| TimerService timerService = sessionCtx.getTimerService();
|
| Collection timers = timerService.getTimers();
| Iterator it = timers.iterator();
| while (it.hasNext()) {
| Timer aTimer = (Timer) it.next();
| if (log.isInfoEnabled()) {
| log.info("checking timer with info " + aTimer.getInfo());
| }
|
| if ((aTimer.getInfo() != null)
| && ((aTimer.getInfo().equals(this.getClass().getName())))) {
| aTimer.cancel();
| if (log.isInfoEnabled()) {
| log.info("Successfully Cancelled "
| + this.getClass().getName());
| }
|
| }
| }
|
| //at this point all timers should be canceled.
| //now we can create our own timer.
|
| Timer timer = timerService.createTimer(0, POLLING_TIME, this.getClass()
| .getName());
| timerHandle = timer.getHandle();
| } catch (Exception e) {
| log.error("An exception occurred while creating the Oncall Timer.",
| e);
| }
| return;
| }
|
|
|
| public void endTimedService() throws EJBException {
| System.out.print ("Inside endTimedService ");
| if (log.isInfoEnabled()) {
| log.info("endTimedService ");
| }
| try {
| TimerService timerService = sessionCtx.getTimerService();
| Collection timers = timerService.getTimers();
| Iterator it = timers.iterator();
| while (it.hasNext()) {
| Timer myTimer = (Timer) it.next();
| if ((myTimer.getInfo().equals(this.getClass().getName()))) {
| myTimer.cancel();
| if (log.isInfoEnabled()) {
| log.info("Successfully Cancelled "
| + this.getClass().getName());
| }
| }
| }
| } catch (Exception e) {
| log.error("Exception after cancelling timer!", e);
| }
| return;
| }
|
|
|
| @Timeout
| public void timeout(Timer timer){
|
| System.out.print ("initiateServiceBean ");
| if (log.isDebugEnabled()) {
| StringBuffer debug = new StringBuffer();
| debug
| .append("OncallTimedService: Searching for requests ready to process.");
| log.debug(debug.toString());
| }
|
| if (!processFlag){
| try {
|
| // set the process flag
| processFlag = true;
|
| // Call getCalendar method of Oncall service object
| oncallService.getCalendar();
| //reset the process flag
| processFlag = false;
| }catch (Throwable t) {
| if (log.isWarnEnabled()) {
| log
| .warn(
| "An exception occurred while searching for the pager forwards.",
| t);
| }
|
| processFlag = false;
|
| throw new EJBException(t.toString());
| }
|
|
| }
| return;
| }
|
|
| }
Also I added following entry in the
C:\jboss-4.2.1.GA\server\tools1\confstandardjboss.xml
<container-configuration>
| <container-name>Singleton oncall Standard Stateless SessionBean</container-name>
| <call-logging>false</call-logging>
| <invoker-proxy-binding-name>stateless-unified-invoker</invoker-proxy-binding-name>
| <container-interceptors>
| <interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor</interceptor>
| <interceptor>org.jboss.ejb.plugins.LogInterceptor</interceptor>
| <interceptor>org.jboss.ejb.plugins.SecurityInterceptor</interceptor>
| <!-- CMT -->
| <interceptor transaction="Container">org.jboss.ejb.plugins.TxInterceptorCMT</interceptor>
| <interceptor transaction="Container">org.jboss.ejb.plugins.CallValidationInterceptor</interceptor>
| <interceptor transaction="Container">org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor</interceptor>
| <!-- BMT -->
| <interceptor transaction="Bean">org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor</interceptor>
| <interceptor transaction="Bean">org.jboss.ejb.plugins.TxInterceptorBMT</interceptor>
| <interceptor transaction="Bean">org.jboss.ejb.plugins.CallValidationInterceptor</interceptor>
| <interceptor>org.jboss.resource.connectionmanager.CachedConnectionInterceptor</interceptor>
| </container-interceptors>
| <instance-pool>org.jboss.ejb.plugins.StatelessSessionInstancePool</instance-pool>
| <instance-cache></instance-cache>
| <persistence-manager></persistence-manager>
| <container-pool-conf>
| <MaximumSize>1</MaximumSize>
| </container-pool-conf>
| </container-configuration>
Other than this i did not do anything.
Thanks
Pramkum.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4215042#4215042
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4215042
17 years, 2 months
[JBoss jBPM] - 3.2.1 Datasource Change
by robro99
I have tried to search, but just cannot seem to find a good answer on this. I apologize as I am a complete noob when it comes to JBOSS. I followed this http://www.jboss.org/community/docs/DOC-11142 and used jbpm-jpdl-suite-3.2.1.zip to get jBPM going. I can start it up and run through the websale example. Now I need to change the backend database.
I think my major problem is that the user guide talks about files that do not exist (at least not in suite-3.2.1). I have been trying to follow this http://docs.jboss.org/jbpm/v3/userguide/thejbpmdatabase.html#d0e2465..
I have a new datasource "mssql-ds.xml" in my C:\jbpm-jpdl-3.2.1\server\server\jbpm\deploy directory. I tested this with a simple JSP and it seems to work. It is named <jndi-name>MSSQLDS</jndi-name>.
The problem I am running into is that the user guide suggests modifying jboss-service.xml which it says is found in
${JBPM_SDK_HOME}/jbpm-server/server/jbpm/deploy/jbpm.sar/META-INF
I do NOT have a jbpm.sar. Is there something equivalent for 3.2.1?
After that step it suggests modifying hibernate.cfg.xml, which it says should be found in jbpm.sar.cfg.jar, which I do not have. :(
If anyone could tell me what file(s) in 3.2.1 I need to modify to change from the default datasource to my new datasource I would be very greatful.
-Rob the confused
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4215041#4215041
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4215041
17 years, 2 months