Subject | Re: java.io.NotSerializableException |
---|---|
Author | Roman Rokytskyy |
Post date | 2003-06-20T14:29:50Z |
Hi,
java.sql.Connection class? General rule is: you cannot put
non-serializable objects into the session.
(for example it was inactive for a long period of time but is still
valid, then container can decide to store it on the disk to save
server memory).
time, only occasionly.
web container so that javax.sql.DataSource instance is accessible via
JNDI and on each request you have to lookup the data source (you can
even store it in the session), obtain the connection from the data
source and close it at the end of each request. You cannot have same
transaction for multiple requests.
Best regards,
Roman Rokytskyy
> I have embedded my Connection Objet inside a session scope Bean inThat's the mistake.
> my web application. This is done just to use the same connection
> along the complete http session.
> Should I change my code design to avoid embedding a Connection objetI do not know what the Connection Object is. Is it an instance of
> in a session scope Bean?
java.sql.Connection class? General rule is: you cannot put
non-serializable objects into the session.
> Is every session scope bean serialized during aNo, session is serialized when web container decides to serialize it.
> http session?
(for example it was inactive for a long period of time but is still
valid, then container can decide to store it on the disk to save
server memory).
> Knowing that java.sql.Connection is not serializable, whyBecause web container does not serialize your session most of the
> my application seems to works fine most of the time?
time, only occasionly.
> What's the best choice to use the same connection in a http session?Not possible. See documentation on J2EE. You need to configure your
web container so that javax.sql.DataSource instance is accessible via
JNDI and on each request you have to lookup the data source (you can
even store it in the session), obtain the connection from the data
source and close it at the end of each request. You cannot have same
transaction for multiple requests.
Best regards,
Roman Rokytskyy