Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass HttpSession to SessionBean?

 
C Balajee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a part of my applications requirement i need to send my session object from my servlet to my Session Bean .
As HttpSession is not serializable It will throw me an Error.
How can i overcome this problem?
regards
Balajee
 
Madhu Juneja
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can pass HttpSession object as part of create method and then maybe you could also declare an object of HttpSession in the Bean class and then store this object from the create method into the Bean class object (as is done for EntityContext or SessionContext in the setXXXContext methods of bean classes.
Yes you are write it will throw error as it is not serializable. May be you can create a sub-class of HttpSession implementing serializable and pass this HttpSession object as part of one of its methods and receive back this object in serialized form. Round-about way, but I am not sure of any other way to pass HttpSession object.

 
C Balajee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried the second option. It Doesn't work.
I tried a wrapper class.
But the requirement of the class implementing serializable is that all its attributes should also be serializable.
In order to overcome this problem i will have to make my HttpSession object in the wrapper class to be transient But that defeats my purpose.
Its acritcal problem the functioning of my application hinges on this.
Thanks for the reply Madhu
regards
Balajee
 
Mark Savory
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please explain what you're trying to do. I think normally the HttpSession has a reference to the EJB SessionBean, not visa-versa.
 
C Balajee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i want to perform "Dirty Read" Check on my Entity Beans(CMP).
We have a class which checks the consistency of each read and write invocations on my Entity Bean.
This class lets call it the "ConsistencyManager" Holds information about who has changed which row and column of the database table, with a timestamp. Whenever a new request for write into entity bean comes into picture the time stamp of the session is used to check whether the user of the session is currently holding consistent data or "Dirty Data".
If the user is holding "Dirty Data" his request is denied.
For the "ConsistencyManager" to work we require data both from the entity bean as well the HttpSession Object.
The "ConsistencyManager" is invoked from the Entity Bean (and it is also a requirement). The Entity Bean will pass all the required information to the "ConsistencyManager" including the 'HttpSession'.
I hope i'm clear this time.
Thanks for your time.
Balajee
 
Madhu Juneja
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make use of Isolation Levels :
� Isolation levels specify locking levels, for example read-only lock on a row, or write lock.
� Read-only lock is optimistic,gives better performance.
� Write lock is pessimistic, ensures better consistency.
� Pessimistic vs. Optimistic is developer's choice.
� Isolation levels are set on a DB connection level using database driver JDBC API.
Isolation Level
An isolation level defines how concurrent transactions to an enterprise information system are isolated
from one another. Enterprise information systems usually support the following the isolation levels:
� ReadCommitted - This level prevents a transaction from reading uncommitted changes from other
transactions.
� RepeatableRead - This level prevents a transaction from reading uncommitted changes from other
transactions. In addition, it ensures that reading the same data multiple times will receive the same value
even if another transaction modifies the data.
� Serializable - This level prevents a transaction from reading uncommitted changes from other transactions and ensures that reading the same data multiple times will receive the same value even if another transaction modifies the data. In addition, it ensures that if a query retrieves a result set based on
a predicate condition and another transaction inserts data that satisfy the predicate condition, re-execution of the query will return the same result set.
Isolation level and concurrency are closely related.
HTH. I have not used Isolation Levels. This is just cut and paste.
 
C Balajee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Madhu,
I also went through the same documentation today morning. I will try to implement it and Let you know the results.
Actually i'm using WebSphere application server. And it is pretty useful with all the redbooks available. We have actually developed a class which will hold all the data of the HttpSession , whih is serializable. I will be trying to pass it to the Entity bean Today.
will update as and when something happens
Regards
Balajee
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic