Kumara SharmaS wrote:Reason being once its null, we cannot persist it to the database.
You can store null to a DB. PreparedStatement has a setNull() method. It may still not make semantic sense for you to do so, but it is allowed.
Also, regarding the title of your
thread, "How to avoid assigning null to a object", note that objects are never null in
Java. Only references can be null. The distinction between a reference and the object it points to (if that reference is not null) is an important one to know and keep in mind.