Hit to all!
We are developing a J2EE application using Sun AS and Hibernate as persistence layer. We are trying to use Hibernate with a Swing user interface but when we try to get the session factory via JNDI we get this exception:
Caused by: java.io.InvalidObjectException: Could not find a SessionFactory named: hibernate/SessionFactory
at org.hibernate.impl.SessionFactoryImpl.readResolve(SessionFactoryImpl.java:622)
... 25 more
This is the Hibernate configuration file:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="session_factory_name">hibernate/SessionFactory</property>
<property name="connection.datasource">jdbc/ItziarDataSource__pm</property>
<property name="connection.release_mode">auto</property>
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<property name="default_batch_fetch_size">16</property>
<property name="transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.SunONETransactionManagerLookup</property>
<property name="jta.UserTransaction">UserTransaction</property>
<property name="transaction.flush_before_completion">true</property>
<property name="transaction.auto_close_session">true</property>
...
We have created a custom resource into the Sun AS:
JNDI Name: hibernate/SessionFactory
A unique identifier Required Field Resource Type: hibernate.SessionFactory
Required Field Factory Class: org.hibernate.impl.SessionFactoryObjectFactory
Factory class for resource; implements javax.naming.spi.ObjectFactory
Description:
Status: Enabled
...
When we start the server obtain this log:
...
[#|2006-01-31T16:56:21.737+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,736 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
|#]
[#|2006-01-31T16:56:21.739+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,739 DEBUG SessionFactoryObjectFactory:76 - registered: 2c9a80c409212dae0109212dc7660000 (hibernate/SessionFactory)
|#]
[#|2006-01-31T16:56:21.740+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,740 INFO SessionFactoryObjectFactory:86 - Factory name: hibernate/SessionFactory
|#]
[#|2006-01-31T16:56:21.741+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,740 INFO NamingHelper:26 - JNDI InitialContext properties:{}
|#]
[#|2006-01-31T16:56:21.741+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,741 DEBUG NamingHelper:48 - binding: hibernate/SessionFactory
|#]
[#|2006-01-31T16:56:21.867+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,865 DEBUG SessionFactoryImpl:659 - serializing: 2c9a80c409212dae0109212dc7660000
|#]
[#|2006-01-31T16:56:21.949+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,948 DEBUG SessionFactoryImpl:661 - serialized
|#]
[#|2006-01-31T16:56:21.978+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,977 DEBUG SessionFactoryImpl:654 - deserializing
|#]
[#|2006-01-31T16:56:21.984+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,983 DEBUG SessionFactoryImpl:656 - deserialized: 2c9a80c409212dae0109212dc7660000
|#]
[#|2006-01-31T16:56:21.985+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,984 DEBUG SessionFactoryImpl:614 - Resolving serialized SessionFactory
|#]
[#|2006-01-31T16:56:21.985+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,985 DEBUG SessionFactoryObjectFactory:145 - lookup: uid=2c9a80c409212dae0109212dc7660000
|#]
[#|2006-01-31T16:56:21.986+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,986 DEBUG SessionFactoryImpl:629 - resolved SessionFactory by uid
|#]
[#|2006-01-31T16:56:21.987+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,987 DEBUG NamingHelper:76 - Bound name: hibernate/SessionFactory
|#]
[#|2006-01-31T16:56:21.988+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,987 INFO SessionFactoryObjectFactory:91 - Bound factory to JNDI name: hibernate/SessionFactory
|#]
[#|2006-01-31T16:56:21.988+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,988 WARN SessionFactoryObjectFactory:101 - InitialContext did not implement EventContext
|#]
[#|2006-01-31T16:56:21.989+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,989 DEBUG SessionFactoryImpl:262 - instantiated session factory
|#]
[#|2006-01-31T16:56:21.989+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,989 DEBUG SessionFactoryImpl:269 - obtaining JTA TransactionManager
|#]
[#|2006-01-31T16:56:21.990+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:21,990 INFO NamingHelper:26 - JNDI InitialContext properties:{}
|#]
[#|2006-01-31T16:56:22.002+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=10;|16:56:22,001 INFO SessionFactoryImpl:379 - Checking 0 named queries
...
But when we try to obtain the SessionFactory via JNDI with this code:
if (null == configFile) {
if (null == sessionFactory){
try{
sessionFactory = (SessionFactory) new InitialContext().lookup(SESSION_FACTORY_JNDI);
return sessionFactory;
}catch(NamingException ne){
ne.printStackTrace();
throw new RuntimeException("The session factory has not been initialized (or an error occured during initialization): " + ne.getMessage());
}
....
we obtain:
Caused by: java.io.InvalidObjectException: Could not find a SessionFactory named: hibernate/SessionFactory
at org.hibernate.impl.SessionFactoryImpl.readResolve(SessionFactoryImpl.java:622)
... 25 more
...
What's wrong? Please help us.
Thank you very much
|