SQL Query to create xml file from sqlserver 2008

Below Query i have use in my project to create xml file directly through SQL Server 2008 by using SQL Query table column value in CDATA

select 1    as Tag,
       null as Parent,
       AIRPORT_ITEM.
       AIRPORT_ID as [AD!1!AIRPORT_ID!CDATA],
       AIRPORT_ITEM.LEVEL1_TITLE as [AD!1!LEVEL1_TITLE!CDATA],
        AIRPORT_ITEM.XML_BLOCK as [AD!1!XML_BLOCK !CDATA],
        AIRPORT.GENDEC_FLAG as [AD!1!GENDEC_FLAG!CDATA]

    
from AIRPORT_ITEM  join AIRPORT 
 ON (AIRPORT_ITEM.AIRPORT_ID = AIRPORT.AIRPORT)
   
for xml explicit

java.lang.ClassCastException During Deserialization in java


At time of deserialization by below code
FileInputStream out= new FileInputStream("c://ser//ser.txt");
ObjectInputStream outs= new ObjectInputStream(out);
      Employee e=(employee)outs.readObject();
If JVM unable to identify the class type i.e. when outs try to call method readObject and programmer given wrong class reference then it will throw  exception

java.lang.ClassCastException: Serlialization.employee1

WriteReplace method concept during Serialization in Java


WriteReplace method use by JVM during Serialization  to indentify the which object user want to searlize .

Below program for better understanding.
package Serlialization;

import java.io.Serializable;

class employee1  implements Serializable
{
      public String sname="king";
      int a;
      employee1()
      {
           
            System.out.println("superclas constructor run");
      }
      public void getNameEmployee1()
      {
            System.out.println("The employee1 getName Employee1");
      }
      /* public  Object readResolve() {
                System.out.println("Read Resolve method calling");
              throw new RuntimeException();
          }*/
     
}

public class employee  implements Serializable
{
      employee1 e= new employee1();
      String name="kumudg";
      int a;
      int c;
      transient int d;
      transient String password="password";
    static String age="raju";
    private Object writeReplace() {
        //System.out.println("The control in writeReplace method");
    return e;
      //return new SerializationProxy(this);
    }

   /*public  Object readResolve() {
        throw new RuntimeException();
    }*/

  public employee()
 
  {
        System.out.println("Inside the employee object contructor ");
  }
 
 
  public void getName()
  {
        System.out.println("Inside the getName method"+name);
       
  }
     
 
 
 
 
}


Serliaztion Test class
package Serlialization;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;


public class serializationTest {
public static void main(String [] args)
{
                serializationTest st= new serializationTest();
                employee e= new employee();
                //employee e=null;
                 st.serializedObject(e);
                //employee de=st.deserializedObject();
                //System.out.println("The value is "+de.name + de.age);
                //System.out.println("The transient value is "+de.password);
    //System.out.println("The transient value is "+de.sname);
               
}


public void serializedObject(employee e)
{
                try {
                                FileOutputStream out= new FileOutputStream("c://ser//ser.txt");
                                ObjectOutputStream outs= new ObjectOutputStream(out);
                                outs.writeObject(e);
                               
                } catch (FileNotFoundException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                }
                catch (Exception e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                }
               
}

}
When programmer will serialize object then employee1 class’s object will searlize because the object return by WriteReplace method in Employee class returning object of Employee1