Hibernate version: 3.0
Hello
I'm trying to serialize my SessionFactory to a file and then deserialize it to save startup-time when developing/testing my (standalone) app. It works fine to save the object to a file, but deserializing next time the app starts does not work.
Please help me if you know what I'm doing wrong! Bye,
Dag W.
Mapping documents:
hibernate.inventory.cfg.xml:
<hibernate-configuration>
<session-factory name="inventory" >
...
Code to store sessionfactory:
Code:
sessionFactory = new Configuration()
.configure( "hibernate.inventory.cfg.xml" )
.buildSessionFactory();
ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream( filename ) );
oos.writeObject( sessionFactory );
oos.close();
Code to read:Code:
ObjectInputStream ois = new ObjectInputStream( new FileInputStream( filename ) );
sessionFactory = ( SessionFactory )ois.readObject();
ois.close();
This is logged when calling readObject on the inputstream:Code:
2006-04-18 10:56:27,018 WARN [main] impl.SessionFactoryObjectFactory: Not found: 59548a9d0aac3659010aac3662030000
2006-04-18 10:56:27,018 WARN [main] impl.SessionFactoryObjectFactory: Not found: inventory
2006-04-18 10:56:27,018 DEBUG [main] util.HibernateInventoryUtil: Exception while reading sessionfactory from file: Could not find a SessionFactory named: inventory
This is also logged when building a new SessionFactory after readObject has failed:
Code:
2006-04-18 10:56:29,909 INFO [main] impl.SessionFactoryImpl: building session factory
2006-04-18 10:56:32,221 INFO [main] impl.SessionFactoryObjectFactory: Factory name: inventory
2006-04-18 10:56:32,221 INFO [main] util.NamingHelper: JNDI InitialContext properties:{}
2006-04-18 10:56:32,221 WARN [main] impl.SessionFactoryObjectFactory: Could not bind factory to JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.getNameParser(InitialContext.java:439)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:260)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
at com.teliasonera.wal.inventory.util.HibernateInventoryUtil.init(HibernateInventoryUtil.java:29)