Discussions

EJB programming & troubleshooting: Data value objects and synchronization

  1. Data value objects and synchronization (3 messages)

    Hi,

    In using data value objects to do course grained transfering of information between client and EJB layers.

    How often and by what mechanism should the front end be updated by the EJB layer. i.e. in keeping the two synchronized.

    You cannot take the front end side and send this to the EJB layer periodically, as the user may not want the changes made on the front end to be submitted yet, so this is should only be done on submission.

    If you try to sync the EJB layer with the front end periodically, this would write over any unsaved front end changes.

    So what is the deal with synchronization?? When and how should it be done?

    Cheers,
  2. One way of solving this is to have a 'datelastmodified' flag in the table of the database from which data is being fetched. Your holder object also needs to have the same flag.

    Assuming two users get the records from the database table with a 'datelastmodified' as 'X'. When the first user tries updating the data, the bean checks the holder 'datelastmodified' against the one in the db( this matches). The modified record is inserted and 'datelastmodified' changes 'Y' in the db. When the second user tries to update the data, the bean should check the date last modified in the db v/s present in the holder ('Y' in the db v/s 'X' in the holder). Since there is a mismatch, it should throw an exception ( indicating that the record which was fetched for display has been modified by some other txn ).

    -Shridhar
  3. There is an interesting and very useful article which might have a solution to your problem:
    http://www.javaworld.com/javaworld/jw-07-2001/jw-0713-optimism.html

    Adnan
  4. For container manged txn: Once the value object has transferred its values to the bean, wouldn't the bean just throw an exception, if a user had updated the record in the meantime.

    Why is the timestamp needed? Is this needed for programmatic txn only?