MaVRoSCy
MaVRoSCy

Reputation: 17849

Non-serializable field in serializable class (transient keyword)

I have a serializable class that extends Servlet

public class FileDownload extends HttpServlet{
  @SuppressWarnings("compatibility:6754389671327954013")
  private static final long serialVersionUID = 1L;
  private ResultSet rset;
  ......
}

My Question is:

Is the rset object automatically converted as transient at compile- or run-time? or do I have to mark it explicitly as transient? (That is a warning brought up from my IDE JDeveloper).

Upvotes: 1

Views: 3500

Answers (2)

Gustav Barkefors
Gustav Barkefors

Reputation: 5086

No, the field is not neglected by serialization - you'll get a java.io.NotSerializableException if you try to serialize an instance of FileDownload. Mark it transient. Btw, what is a ResultSet doing as a field in a Servlet? This is not thread-safe. ResultSets should be local variables only, in any context.

Upvotes: 2

UVM
UVM

Reputation: 9914

You have to call transient your own.But you cannot serialize an object unless it implements Serializable interface.ResultSet is such kind of object.

Upvotes: 0

Related Questions