-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Unable to serialize/deserialize SessionFactory
PostPosted: Thu Apr 20, 2006 7:08 am 
Newbie

Joined: Thu Mar 23, 2006 11:14 am
Posts: 6
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)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 8:14 am 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
SessionFactory serialisation is only there to support JNDI - see Max's comment on http://opensource.atlassian.com/project ... wse/HB-492

The Configuration is serialisable though, so you may be able to use that to speed up your startup time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.