• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot serialize session attribute

 
Shahid Kahn
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am getting following exception. I have no clue to solve it. Can anyone please help figure out the problem here?
 
Paul Clapham
Sheriff
Posts: 21869
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You tried to put an object into your session which isn't serializable. That isn't allowed because the Tomcat code may need to write the contents of your session to some external location for various reasons.

And it appears that you tried to put a JDBC connection (or rather, the connection from a connection pool) into your session. Why did you do that? You shouldn't hang onto a session for any longer than a single request, and there's no point in doing so. Just get a connection from the pool every time you need one.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:You shouldn't hang onto a session for any longer than a single request,

I'm sure that here, Paul meant connection, rather than session.

In fact, your presentation code shouldn't be dealing with connections at all. Connections should be handled deep within the model layer, and retained for the shortest duration possible.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!