×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

HELP!!!! How to use Session Bean to query and update MS Access database? How to make multiple EJB instances update MS Access database correctly?

本文发表在 rolia.net 枫下论坛In a distributed J2EE application we are developing, a stateless session bean is used to query and update MS Acess database in 3 steps: (1) Get the maximum ID from the first table where ID is the primary key. (2) Insert a row into the first table using the ID+1 as the primary key . (3) Insert a row into another two tables using ID+1 as foreign key.

We use JBoss 3.0 as application server. Because this is distributed application, there are more than one session bean instances running at the same time in the EJB container. When one EJB instance is running at the 2nd step (not finishing the inserting), another EJB instance will be running at the 1st step. Therefore, the 2nd EJB instance will get the same ID and thus causes SQL exceptions. How to deal with this?

Another issue is when one EJB instance is running at the 2nd or 3rd step, other EJB instances that try to update MS Access table will also cause a SQL exception. This is because the database cannot be updated by two EJB at the same time. How to deal with this?

Because MS access does not support transaction, we cannot use SQL transactions. How to make Step 1 to 3 completed by one EJB instance before another EJB instance executes step 1?

I cannot input Chinese. Your response is highly appreciated.

Thanks!!!更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / HELP!!!! How to use Session Bean to query and update MS Access database? How to make multiple EJB instances update MS Access database correctly?
    本文发表在 rolia.net 枫下论坛In a distributed J2EE application we are developing, a stateless session bean is used to query and update MS Acess database in 3 steps: (1) Get the maximum ID from the first table where ID is the primary key. (2) Insert a row into the first table using the ID+1 as the primary key . (3) Insert a row into another two tables using ID+1 as foreign key.

    We use JBoss 3.0 as application server. Because this is distributed application, there are more than one session bean instances running at the same time in the EJB container. When one EJB instance is running at the 2nd step (not finishing the inserting), another EJB instance will be running at the 1st step. Therefore, the 2nd EJB instance will get the same ID and thus causes SQL exceptions. How to deal with this?

    Another issue is when one EJB instance is running at the 2nd or 3rd step, other EJB instances that try to update MS Access table will also cause a SQL exception. This is because the database cannot be updated by two EJB at the same time. How to deal with this?

    Because MS access does not support transaction, we cannot use SQL transactions. How to make Step 1 to 3 completed by one EJB instance before another EJB instance executes step 1?

    I cannot input Chinese. Your response is highly appreciated.

    Thanks!!!更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • Using unique id generator
      • How can I do that? Using a singleton? Thanks again.
    • Synchronization in ejb???
      For example, in the following code:

      public boolean foo(int val) {
      //...
      helper.set(val);
      int val2 = helper.get(val);
      //...
      return (val==val2);
      }

      where foo is a method of a stateless session bean, and helper is the instance of a help class, a singleton object.

      Can foo always return true if i don't use "synchronized(helper)"?

      The answer is no because EJB's act sort of like threads - everyone can have their own ejb instance, and if multiple ejb instances (like multiple threads) act on shared data (such as the private member of a singleton) there will be concurrency issues.

      How to synchronize EJB?
      • stateless session bean不应该含有任何可以被不同instance share的property,否则就不是threads safe的了。还是从数据库考虑吧。
    • stateless session bean有多少个instance不是受你控制的,你不能singleton它。理论上它只能包含stateless的business logic。而且synchronization也不受你控制。我的理解是:唯一的做法就是lock住table,但是我不懂access,不知道怎么做。
    • 这个问题是如何处理concurrency的问题,和ejb, session bean没有关系。在大型数据库里面如Oracle是用sequence number解决,access里面应该也有相应的办法,google一下吧。