ClassHasNoFields

This diagnostic type provides information about classes in your persistent class hierarchy that have no persistent fields. The diagnostic message appears when the class is saved to the database. It is recommended to remove such classes from the database to avoid the overhead for the maintenance of class indexes.

Let's look at the following example:

Empty.java
01package com.db4odoc.f1.diagnostics; 02 03import java.util.Calendar; 04import java.text.DateFormat; 05 06 07public class Empty { 08 09 public Empty() { 10 } 11 12 public String CurrentTime() 13 { 14 Calendar cl = Calendar.getInstance(); 15 DateFormat df = DateFormat.getDateTimeInstance(); 16 String time = df.format(cl.getTime()); 17 return time; 18 } 19 20 public String ToString() 21 { 22 return CurrentTime(); 23 } 24}

DiagnosticExample.java: setEmptyObject
1private static void setEmptyObject(ObjectContainer db){ 2 Empty empty = new Empty(); 3 db.set(empty); 4 }

DiagnosticExample.java: testEmpty
01public static void main(String[] args){ 02 testEmpty(); 03 testArbitrary(); 04 testIndexDiagnostics(); 05 testTranslatorDiagnostics(); 06 } 07 // end main 08 public static void testEmpty() { 09 Db4o.configure().diagnostic().addListener(new DiagnosticToConsole()); 10 new File(YAPFILENAME).delete(); 11 ObjectContainer db=Db4o.openFile(YAPFILENAME); 12 try { 13 setEmptyObject(db); 14 } 15 finally { 16 db.close(); 17 Db4o.configure().diagnostic().removeAllListeners(); 18 } 19 }

>

Diagnostic message is produced when the execution point reaches

db.set(empty)

Empty class does not keep any information and can be left in the application code; there is no need to put it in the database.