??????? Configuration configuration=null;
??????? try {
??????????? Configuration configurationSerializable = new Configuration();
??????????? FileOutputStream fos = new FileOutputStream("serial");
??????????? ObjectOutputStream oos = new ObjectOutputStream(fos);
??????????? oos.writeObject(configurationSerializable);
??????????? oos.flush();
??????????? oos.close();
??????? } catch (FileNotFoundException e) {
??????????? e.printStackTrace();? //To change body of catch statement use File | Settings | File Templates.
??????? }
??????? catch (IOException e) {
??????????? e.printStackTrace();? //To change body of catch statement use File | Settings | File Templates.
??????? }
??????? try {
??????????? FileInputStream fis = new FileInputStream("serial");
??????????? ObjectInputStream ois = new ObjectInputStream(fis);
??????????? configuration = (Configuration) ois.readObject();
??????????? ois.close();
??????? } catch (FileNotFoundException e) {
??????????? e.printStackTrace();? //To change body of catch statement use File | Settings | File Templates.
??????? }
??????? catch (IOException e) {
??????????? e.printStackTrace();? //To change body of catch statement use File | Settings | File Templates.
??????? }
??????? catch (ClassNotFoundException e) {
??????????? e.printStackTrace();? //To change body of catch statement use File | Settings | File Templates.
??????? }
??????? if(configuration!=null)
??????? {
??????? SessionFactory sessionFactory = configuration.configure().buildSessionFactory();
??????? Session session = sessionFactory.openSession();
??????? Transaction transaction = session.beginTransaction();
??????? callBack.doing(session);
??????? transaction.commit();
??????? }
??? }
when will Configuration serialize and why it's some field seted transient?the example will be error because some field transient is null after serialize.
posted on 2006-10-30 16:40
R.Zeus 閱讀(366)
評論(0) 編輯 收藏 所屬分類:
Hibernate 、
J2SE