Announcement Announcement Module
Collapse
No announcement yet.
prevent concurrent users to do a same action(method) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • prevent concurrent users to do a same action(method)

    Hi all,
    I have a problem when two users press a method at the same time:

    the mothod in the Action is:

    @Override
    public Event addEntity(RequestContext context) throws ActionException {
    try {
    correctBinding(context);
    List<BaseEntity> newList = myService.savemyEntity(myEntity, user, department);

    }


    return success();
    } catch (ActionException e) { }


    the mothod in the Service is:

    @Transactional
    public List<BaseEntity> savemyEntity(MyEntity myEntity, User user, Department department) throws myServiceRuleException {
    try {

    some set methods.....

    payment = (Payment ) crudService.add(payment);---> database error unique constraint(Could not execute JDBC batch update; SQL [insert into table............)
    } catch (ServiceException e) {
    throw new myServiceRuleException(e);


    }
    return payment ;
    }

  • #2
    Originally posted by mehi View Post
    Hi all,
    I have a problem when two users press a method at the same time:

    the mothod in the Action is:

    @Override
    public Event addEntity(RequestContext context) throws ActionException {
    try {
    correctBinding(context);
    List<BaseEntity> newList = myService.savemyEntity(myEntity, user, department);

    }


    return success();
    } catch (ActionException e) { }


    the mothod in the Service is:

    @Transactional
    public List<BaseEntity> savemyEntity(MyEntity myEntity, User user, Department department) throws myServiceRuleException {
    try {

    some set methods.....

    payment = (Payment ) crudService.add(payment);---> database error unique constraint(Could not execute JDBC batch update; SQL [insert into table............)
    } catch (ServiceException e) {
    throw new myServiceRuleException(e);


    }
    return payment ;
    }

    Please use <code> for code samples.

    That said, I'm not sure that spring security is the right place to solve your problem. Typically you would prevent two users from modifying the same object by making sure your application implements optimistic locking.

    But based on your exception, you're running into issues on insert rather than update. Which is curious. is the constraint violation by chance on the primary key?

    Comment


    • #3
      Originally posted by arthomps View Post
      Please use <code> for code samples.

      That said, I'm not sure that spring security is the right place to solve your problem. Typically you would prevent two users from modifying the same object by making sure your application implements optimistic locking.

      But based on your exception, you're running into issues on insert rather than update. Which is curious. is the constraint violation by chance on the primary key?
      Thanks for your reply
      I get the exception(Unique Constraint) exactly here
      <code>
      masterObject= (MasterObject) crudService.add(masterObject);
      detailObject= (DetailObject) crudService.add(detailObject);// I get the exception here
      </code>
      I use Oracle as my DB.
      Thank you for any kind of suggestions

      Comment


      • #4
        Originally posted by mehi View Post
        Thanks for your reply
        I get the exception(Unique Constraint) exactly here
        <code>
        masterObject= (MasterObject) crudService.add(masterObject);
        detailObject= (DetailObject) crudService.add(detailObject);// I get the exception here
        </code>
        I use Oracle as my DB.
        Thank you for any kind of suggestions
        No one knows the solution........

        Comment


        • #5
          It seems to me you either have a mapping problem (let hibernate manage your dependend objects that is what you use a ORM mapper for) or a transaction problem. The whole method should be a single transaction not multiple.

          Comment

          Working...
          X