Announcement Announcement Module
Collapse
No announcement yet.
singleton issue with AOP implementation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • singleton issue with AOP implementation

    Okay, Following is the requirement.

    We have JSF layer, Controller layer, Service Layer and DAO layer in our application. We want, whenever we insert some data into database, it will get inserted along with the login user's id, so that it can be tracked who has inserted it.

    We are using AOP feature at the DAO layer for this, so that any "save" method coming through the DAO layer gets pointcut at this stage, and the user id gets inserted into the object before going to the Database.

    We are taking the user id from the session at the controller level, and putting it into a singleton class (IdentityManager). Because Session is not available at the DAO layer, we get the user id here from that singleton class.

    So far so good. It is working perfectly for single login. Now the problem is happenning with multiple login. It is always taking the last login user id while inserting.

    Say, in one session I login with user_1, another session I login with user_2. Now user_2 has logged in last, so if I insert anything from user_1 login, IdentityManager class passes id as "user_2" to be inserted with. Because it is a singleton class, it is maintaining single instance only and gets updated with the latest value only.

    We tried even with using ThreadLocal, but ThreadLocal does not solve the issue because Spring serves a single thread model, ThreadLocal cannot show its magic in Spring framework.

    Can somebody help in this regard?

    TIA,
    Samik

  • #2
    Originally posted by bondhutto
    We tried even with using ThreadLocal, but ThreadLocal does not solve the issue because Spring serves a single thread model, ThreadLocal cannot show its magic in Spring framework.
    Not sure how ThreadLocal doesn't work in your case - IIRC, it's exactly what Acegi uses to pass along security context data.

    Comment

    Working...
    X