Bon, voilà, il y avait, entre autres, un driver non chargé. J'en suis au stade suivant :
- 1° Dans mon application Swing, je récupère mon fichier
properties et crée un objet
Properties pour hibernate sur base de mes clefs.
- 2° J'instancie mon objet
HibernateUtil en lui passant l'objet
Properties
- 3° L'objet
HibernateUtil crée un
Configuration sur base des
Properties que je lui passe et du fichier 'hibernate.cfg.xml'.
Tou semble bien se passer, j'ai des logs "correctes" :
Quote:
2008-09-02 11:47:15,843 INFO [org.hibernate.cfg.Environment] - Hibernate 3.2.5
2008-09-02 11:47:15,843 INFO [org.hibernate.cfg.Environment] - hibernate.properties not found
2008-09-02 11:47:15,843 INFO [org.hibernate.cfg.Environment] - Bytecode provider name : cglib
2008-09-02 11:47:15,875 INFO [org.hibernate.cfg.Environment] - using JDK 1.4 java.sql.Timestamp handling
2008-09-02 11:47:15,921 INFO [org.hibernate.cfg.Configuration] - configuring from file: hibernate.cfg.xml
2008-09-02 11:47:16,000 INFO [org.hibernate.cfg.Configuration] - Configured SessionFactory: null
2008-09-02 11:47:16,000 INFO [org.hibernate.cfg.Configuration] - Reading mappings from resource : xx/yy/mappings/nationality.hbm.xml
2008-09-02 11:47:16,140 INFO [org.hibernate.cfg.Configuration] - configuring from resource: /hibernate.cfg.xml
2008-09-02 11:47:16,140 INFO [org.hibernate.cfg.Configuration] - Configuration resource: /hibernate.cfg.xml
2008-09-02 11:47:16,156 INFO [org.hibernate.cfg.Configuration] - Configured SessionFactory: SessionFactory
2008-09-02 11:47:16,203 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - Using Hibernate built-in connection pool (not for production use!)
2008-09-02 11:47:16,203 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - Hibernate connection pool size: 1
2008-09-02 11:47:16,203 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - autocommit mode: false
2008-09-02 11:47:16,203 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/MYDB
2008-09-02 11:47:16,203 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - connection properties: {user=MYUSER, password=MYPASSWORD}
2008-09-02 11:47:16,328 INFO [org.hibernate.cfg.SettingsFactory] - RDBMS: PostgreSQL, version: 8.2.7
2008-09-02 11:47:16,328 INFO [org.hibernate.cfg.SettingsFactory] - JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.2 JDBC3 with SSL (build 505)
..
Mais, esnuite je reçois l'exception suivante :
Quote:
2008-09-02 11:47:16,625 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] - initializing class SessionFactoryObjectFactory
2008-09-02 11:47:16,625 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] - registered: 2c90858a1c22757a011c22757b110000 (SessionFactory)
2008-09-02 11:47:16,625 INFO [org.hibernate.impl.SessionFactoryObjectFactory] - Factory name: SessionFactory
2008-09-02 11:47:16,625 INFO [org.hibernate.util.NamingHelper] - JNDI InitialContext properties:{}
2008-09-02 11:47:16,625 DEBUG [org.hibernate.util.NamingHelper] - binding: SessionFactory
2008-09-02 11:47:16,625 WARN [org.hibernate.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:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.getNameParser(InitialContext.java:480)
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:306)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at xx.yy.hibernate.HibernateUtil.<init>(HibernateUtil.java:46)
Voici mon code de
HibernateUtil :
Code:
public HibernateUtil(Properties properties, File hibernateCfg) {
Configuration cfg = new Configuration()
.setProperties(properties)
.configure(hibernateCfg)
// Mappings
.addResource("xx/yy/mappings/nationality.hbm.xml")
.configure();
try {
sessionFactory = cfg.buildSessionFactory();
} catch (Throwable e) {
throw new ExceptionInInitializerError(e);
}
}
Je ne comprend pas ce qui lui manque, mon fichier de configuration d'hiberante est le suivant :
Quote:
<hibernate-configuration>
<session-factory>
<!--
From administaror properties file (user editable properties)
<property name="hibernate.connection.url"></property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>
-->
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">validate</property>
</session-factory>
</hibernate-configuration>