It's not a secret anymore!*
The moose likes EJB and other Java EE Technologies and the fly likes How to pass HttpSession to SessionBean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to pass HttpSession to SessionBean?" Watch "How to pass HttpSession to SessionBean?" New topic
Author

How to pass HttpSession to SessionBean?

C Balajee
Greenhorn

Joined: Oct 18, 2000
Posts: 25
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

Joined: Mar 10, 2001
Posts: 176
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

Joined: Oct 18, 2000
Posts: 25
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

Joined: Feb 08, 2001
Posts: 122
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

Joined: Oct 18, 2000
Posts: 25
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

Joined: Mar 10, 2001
Posts: 176
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

Joined: Oct 18, 2000
Posts: 25
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
 
Don't get me started about those stupid light bulbs.
 
subject: How to pass HttpSession to SessionBean?