Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1116 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  hsqldb et hibernate.config.xml

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

hsqldb et hibernate.config.xml

n°1877945
the_frogki​ller
Posté le 26-04-2009 à 17:36:17  profilanswer
 

bonjour,
 
je développe une application en Swing qui doit stocker les données associées dans une hsqlDB en local. Cela marche très bien.
mon problèmes est que chaque utilisateur doit avoir sa petite base de donnée de sauvegarde dont la localisation est configurable par l'utilisateur.
donc ma question est: comment indiquer l'url de la BD à hibernate quand elle est configurable au niveau applicatif?
 
le petit bout de code du main de test:

Code :
  1. SessionFactory sessionFactory = null;
  2.  try {
  3.             // Création de la SessionFactory à partir de hibernate.cfg.xml
  4.          Configuration cfg = new Configuration().configure();
  5.          String url = "jdbc:hsqldb:file:G:\\java\\tests\\testDB2\\MyDB.userDB";
  6.          cfg.getProperties().setProperty("connection.url", url);
  7.        
  8.             sessionFactory = cfg.buildSessionFactory();
  9.         } catch (Throwable ex) {
  10.             // Make sure you log the exception, as it might be swallowed
  11.             System.err.println("Initial SessionFactory creation failed." + ex);
  12.             throw new ExceptionInInitializerError(ex);
  13.         }
  14.         Session session = sessionFactory.openSession();
  15.         Transaction transaction = session.beginTransaction();


 
mon hibernate.cfg.xml :

Code :
  1. <?xml version='1.0' encoding='utf-8'?>
  2. <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  3. <hibernate-configuration>
  4.     <session-factory>
  5.         <!-- Database connection settings -->
  6.         <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
  7.          <property name="connection.url">jdbc:hsqldb:file:G:\java\tests\testDB\CompteDB.monCompte</property> 
  8.      <property name="connection.username">sa</property>
  9.         <property name="connection.password"></property>
  10.         <!-- JDBC connection pool (use the built-in) -->
  11.         <property name="connection.pool_size">1</property>
  12.         <!-- SQL dialect -->
  13.         <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
  14.         <!-- Enable Hibernate's automatic session context management -->
  15.         <property name="current_session_context_class">thread</property>
  16.         <!-- Disable the second-level cache 
  17.         <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> -->
  18.         <!-- Echo all executed SQL to stdout -->
  19.         <property name="show_sql">true</property>
  20.         <!-- Drop and re-create the database schema on startup  -->
  21.         <property name="hbm2ddl.auto">create</property>
  22.         <mapping resource="appli/Compte.hbm.xml"/> 
  23.     </session-factory>


 
et enfin les logs :

Code :
  1. 13:44:05,951  INFO Environment:456 - Hibernate 3.0rc1
  2. 13:44:05,955  INFO Environment:469 - hibernate.properties not found
  3. 13:44:05,959  INFO Environment:502 - using CGLIB reflection optimizer
  4. 13:44:05,961  INFO Environment:532 - using JDK 1.4 java.sql.Timestamp handling
  5. 13:44:05,963  INFO Configuration:1228 - configuring from resource: /hibernate.cfg.xml
  6. 13:44:05,964  INFO Configuration:1199 - Configuration resource: /hibernate.cfg.xml
  7. 13:44:06,110  INFO Configuration:439 - Mapping resource: appli/Compte.hbm.xml
  8. 13:44:06,286  INFO HbmBinder:256 - Mapping class: appli.Compte -> COMPTE
  9. 13:44:06,331  INFO Configuration:1340 - Configured SessionFactory: null
  10. 13:44:16,778  INFO Configuration:844 - processing extends queue
  11. 13:44:16,779  INFO Configuration:848 - processing collection mappings
  12. 13:44:16,779  INFO Configuration:857 - processing association property references
  13. 13:44:16,779  INFO Configuration:884 - processing foreign key constraints
  14. 13:44:16,829  INFO Dialect:89 - Using dialect: org.hibernate.dialect.HSQLDialect
  15. 13:44:16,834  INFO SettingsFactory:90 - Default batch fetch size: 1
  16. 13:44:16,834  INFO SettingsFactory:94 - Generate SQL with comments: disabled
  17. 13:44:16,834  INFO SettingsFactory:98 - Order SQL updates by primary key: disabled
  18. 13:44:16,834  INFO SettingsFactory:273 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
  19. 13:44:16,836  INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
  20. 13:44:16,837  INFO SettingsFactory:106 - Query language substitutions: {}
  21. 13:44:16,839  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
  22. 13:44:16,839  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
  23. 13:44:16,839  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
  24. 13:44:16,843  INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:file:G:\java\tests\testDB\CompteDB.monCompte
  25. 13:44:16,843  INFO DriverManagerConnectionProvider:86 - connection properties: {user=sa, password=****}
  26. 13:44:17,077  INFO SettingsFactory:148 - JDBC batch size: 15
  27. 13:44:17,077  INFO SettingsFactory:151 - JDBC batch updates for versioned data: disabled
  28. 13:44:17,078  INFO SettingsFactory:156 - Scrollable result sets: enabled
  29. 13:44:17,078  INFO SettingsFactory:164 - JDBC3 getGeneratedKeys(): disabled
  30. 13:44:17,080  INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
  31. 13:44:17,081  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
  32. 13:44:17,082  INFO SettingsFactory:176 - Automatic flush during beforeCompletion(): disabled
  33. 13:44:17,082  INFO SettingsFactory:179 - Automatic session close at end of transaction: disabled
  34. 13:44:17,082  INFO SettingsFactory:260 - Cache provider: org.hibernate.cache.EhCacheProvider
  35. 13:44:17,084  INFO SettingsFactory:187 - Second-level cache: enabled
  36. 13:44:17,084  INFO SettingsFactory:192 - Optimize cache for minimal puts: disabled
  37. 13:44:17,085  INFO SettingsFactory:199 - Structured second-level cache entries: enabled
  38. 13:44:17,085  INFO SettingsFactory:203 - Query cache: disabled
  39. 13:44:17,085  INFO SettingsFactory:210 - Echoing all SQL to stdout
  40. 13:44:17,085  INFO SettingsFactory:214 - Statistics: disabled
  41. 13:44:17,085  INFO SettingsFactory:218 - Deleted entity synthetic identifier rollback: disabled
  42. 13:44:17,086  INFO SettingsFactory:232 - Default entity-mode: pojo
  43. 13:44:17,212  INFO SessionFactoryImpl:140 - building session factory
  44. 13:44:17,217  WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/G:/java/librairies/libHibernate/ehcache-1.1.jar!/ehcache-failsafe.xml
  45. 13:44:17,439  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
  46. 13:44:17,442  INFO Dialect:89 - Using dialect: org.hibernate.dialect.HSQLDialect
  47. 13:44:17,442  INFO Configuration:844 - processing extends queue
  48. 13:44:17,442  INFO Configuration:848 - processing collection mappings
  49. 13:44:17,442  INFO Configuration:857 - processing association property references
  50. 13:44:17,442  INFO Configuration:884 - processing foreign key constraints
  51. 13:44:17,443  INFO Configuration:844 - processing extends queue
  52. 13:44:17,443  INFO Configuration:848 - processing collection mappings
  53. 13:44:17,443  INFO Configuration:857 - processing association property references
  54. 13:44:17,443  INFO Configuration:884 - processing foreign key constraints
  55. 13:44:17,443  INFO SchemaExport:100 - Running hbm2ddl schema export
  56. 13:44:17,444  INFO SchemaExport:121 - exporting generated schema to database
  57. 13:44:17,444  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
  58. 13:44:17,444  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
  59. 13:44:17,445  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
  60. 13:44:17,446  INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:file:G:\java\tests\testDB\CompteDB.monCompte
  61. 13:44:17,446  INFO DriverManagerConnectionProvider:86 - connection properties: {user=sa, password=****}
  62. 13:44:17,449 DEBUG SchemaExport:136 - drop table COMPTE if exists
  63. 13:44:17,449 DEBUG SchemaExport:154 - create table COMPTE (
  64.    ID_COMPTE integer not null,
  65.    NOM_COMPTE varchar(255),
  66.    NOM_BANQUE varchar(255),
  67.    SOLDE_INITIAL double,
  68.    primary key (ID_COMPTE)
  69. )
  70. 13:44:17,454  INFO SchemaExport:166 - schema export complete
  71. 13:44:17,455  INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:hsqldb:file:G:\java\tests\testDB\CompteDB.monCompte
  72. 13:44:17,455  INFO SessionFactoryImpl:366 - Checking 0 named queries
  73. 13:44:17,487  INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:hsqldb:file:G:\java\tests\testDB\CompteDB.monCompte
  74. Hibernate: insert into COMPTE (NOM_COMPTE, NOM_BANQUE, SOLDE_INITIAL, ID_COMPTE) values (?, ?, ?, ?)
  75. Hibernate: select compte0_.ID_COMPTE as ID1_, compte0_.NOM_COMPTE as NOM2_0_, compte0_.NOM_BANQUE as NOM3_0_, compte0_.SOLDE_INITIAL as SOLDE4_0_ from COMPTE compte0_


 
merci d'avance

mood
Publicité
Posté le 26-04-2009 à 17:36:17  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  hsqldb et hibernate.config.xml

 

Sujets relatifs
hibernate problème[Hibernate] Instanciation nulle de l'id d'un idbag
pb debutant installation et config de mysqlComment synchroniser Hibernate avec base de données???
Requete SQL HibernateHibernate
JUnit Hibernate Acces BDHibernate criteria subquery
[résolu] Hibernate Annotations et oneToMany EAGER 
Plus de sujets relatifs à : hsqldb et hibernate.config.xml


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR