bonsoir,

voilà en attendant de trouver une solution à mon problème pour mon précédent post un autre problème se pose à moi.

pour contourner le problème du drop des tables à cause de la balise
Code : Sélectionner tout - Visualiser dans une fenêtre à part
<property name="hbm2ddl.auto">create</property>
dans l'hibernate.cfg.xml je l'ais remplacé par "update".

du coup il faut que j'initialise la base de donnée au premier lancement. Bizarrement la création semble bien se dérouler mais hibernate est incapable de trouver la table COMPTE. étrangement je peut faire des insert et des select en sql sans problèmes.

voilà les bouts de codes de test.

le main:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
try {
        	String creatTableCompte = "create table COMPTE (ID_COMPTE integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,NOM_COMPTE varchar(255),"
            	+ "NOM_BANQUE varchar(255),SOLDE_INITIAL double)";
 
        	Class.forName("org.hsqldb.jdbcDriver").newInstance();
        	Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:G:\\java\\tests\\testDB1\\MyDB1.userDB1", "sa", "");
            Statement st = conn.createStatement();
            st.executeUpdate(creatTableCompte);
            st.executeQuery("SHUTDOWN");
            st.close();
            conn.close();
            } catch (Exception e) {
                System.err.println("Got an exception! ");
                e.printStackTrace();
                System.exit(0);
            }
 
 
		SessionFactory sessionFactory = null;
		try {
            // Création de la SessionFactory à partir de hibernate.cfg.xml
			Configuration config = new Configuration().configure();
            sessionFactory = config.buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
 
 
        Session session = sessionFactory.openSession();
        Transaction transaction = session.beginTransaction();
 
        List result = session.createQuery("from Compte").list();
 
		 Compte compte = new Compte();
		 compte.setNomBanque("zou");
		 compte.setNomCompte("meuhhhh");
		 compte.setSoldeInitial(0);
		 session.persist(compte);
		 session.save(compte);
		 try {
			session.flush();
 
			result = session.createQuery("from Compte").list();
 
			transaction.commit();
		 } catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		 session.close();
et le hobernate.cfg.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 
<hibernate-configuration>
 
    <session-factory>
 
        <!-- Database connection settings -->
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:file:G:\java\tests\testDB1\MyDB1.userDB1</property>  
    	<property name="connection.username">sa</property>
        <property name="connection.password"></property>
 
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
 
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
 
        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
 
        <!-- Disable the second-level cache  
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> -->
 
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql" >true</property>
 
        <!-- Drop and re-create the database schema on startup  -->
        <property name="hbm2ddl.auto">update</property>  
 
        <mapping resource="appli/Compte.hbm.xml"/>  
 
    </session-factory>
 
</hibernate-configuration>
et les logs:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
00:13:35,665  INFO Environment:456 - Hibernate 3.0rc1
00:13:35,668  INFO Environment:469 - hibernate.properties not found
00:13:35,669  INFO Environment:502 - using CGLIB reflection optimizer
00:13:35,670  INFO Environment:532 - using JDK 1.4 java.sql.Timestamp handling
00:13:35,671  INFO Configuration:1228 - configuring from resource: /hibernate.cfg.xml
00:13:35,671  INFO Configuration:1199 - Configuration resource: /hibernate.cfg.xml
00:13:35,755  INFO Configuration:439 - Mapping resource: appli/Compte.hbm.xml
00:13:35,824  INFO HbmBinder:256 - Mapping class: appli.Compte -> COMPTE
00:13:35,841  INFO Configuration:1340 - Configured SessionFactory: null
00:13:35,841  INFO Configuration:844 - processing extends queue
00:13:35,842  INFO Configuration:848 - processing collection mappings
00:13:35,842  INFO Configuration:857 - processing association property references
00:13:35,842  INFO Configuration:884 - processing foreign key constraints
00:13:35,896  INFO Dialect:89 - Using dialect: org.hibernate.dialect.HSQLDialect
00:13:35,902  INFO SettingsFactory:90 - Default batch fetch size: 1
00:13:35,903  INFO SettingsFactory:94 - Generate SQL with comments: disabled
00:13:35,903  INFO SettingsFactory:98 - Order SQL updates by primary key: disabled
00:13:35,903  INFO SettingsFactory:273 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
00:13:35,904  INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
00:13:35,905  INFO SettingsFactory:106 - Query language substitutions: {}
00:13:35,907  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
00:13:35,907  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
00:13:35,908  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
00:13:35,912  INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:file:G:\java\tests\testDB1\MyDB1.userDB1
00:13:35,912  INFO DriverManagerConnectionProvider:86 - connection properties: {user=sa, password=****}
00:13:36,137  INFO SettingsFactory:148 - JDBC batch size: 15
00:13:36,138  INFO SettingsFactory:151 - JDBC batch updates for versioned data: disabled
00:13:36,138  INFO SettingsFactory:156 - Scrollable result sets: enabled
00:13:36,138  INFO SettingsFactory:164 - JDBC3 getGeneratedKeys(): disabled
00:13:36,140  INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
00:13:36,142  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
00:13:36,142  INFO SettingsFactory:176 - Automatic flush during beforeCompletion(): disabled
00:13:36,142  INFO SettingsFactory:179 - Automatic session close at end of transaction: disabled
00:13:36,142  INFO SettingsFactory:260 - Cache provider: org.hibernate.cache.EhCacheProvider
00:13:36,145  INFO SettingsFactory:187 - Second-level cache: enabled
00:13:36,145  INFO SettingsFactory:192 - Optimize cache for minimal puts: disabled
00:13:36,145  INFO SettingsFactory:199 - Structured second-level cache entries: enabled
00:13:36,147  INFO SettingsFactory:203 - Query cache: disabled
00:13:36,147  INFO SettingsFactory:210 - Echoing all SQL to stdout
00:13:36,147  INFO SettingsFactory:214 - Statistics: disabled
00:13:36,147  INFO SettingsFactory:218 - Deleted entity synthetic identifier rollback: disabled
00:13:36,148  INFO SettingsFactory:232 - Default entity-mode: pojo
00:13:36,269  INFO SessionFactoryImpl:140 - building session factory
00:13:36,277  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
00:13:36,523  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
00:13:36,525  INFO Dialect:89 - Using dialect: org.hibernate.dialect.HSQLDialect
00:13:36,525  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
00:13:36,525  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
00:13:36,525  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
00:13:36,526  INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:file:G:\java\tests\testDB1\MyDB1.userDB1
00:13:36,526  INFO DriverManagerConnectionProvider:86 - connection properties: {user=sa, password=****}
00:13:36,526  INFO SchemaUpdate:105 - Running hbm2ddl schema update
00:13:36,526  INFO SchemaUpdate:117 - fetching database metadata
00:13:36,538 ERROR SchemaUpdate:129 - could not get database metadata
java.sql.SQLException: Table not found in statement [select sequence_name from system_sequences]
	at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
	at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
	at org.hsqldb.jdbc.jdbcStatement.executeQuery(Unknown Source)
	at org.hibernate.tool.hbm2ddl.DatabaseMetadata.initSequences(DatabaseMetadata.java:113)
	at org.hibernate.tool.hbm2ddl.DatabaseMetadata.<init>(DatabaseMetadata.java:39)
	at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:124)
	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:252)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043)
	at appli.Test.main(Test.java:134)
00:13:36,539 ERROR SchemaUpdate:158 - could not complete schema update
java.sql.SQLException: Table not found in statement [select sequence_name from system_sequences]
	at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
	at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
	at org.hsqldb.jdbc.jdbcStatement.executeQuery(Unknown Source)
	at org.hibernate.tool.hbm2ddl.DatabaseMetadata.initSequences(DatabaseMetadata.java:113)
	at org.hibernate.tool.hbm2ddl.DatabaseMetadata.<init>(DatabaseMetadata.java:39)
	at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:124)
	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:252)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043)
	at appli.Test.main(Test.java:134)
00:13:36,540  INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:hsqldb:file:G:\java\tests\testDB1\MyDB1.userDB1
00:13:36,540  INFO SessionFactoryImpl:366 - Checking 0 named queries
00:13:36,589  INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:hsqldb:file:G:\java\tests\testDB1\MyDB1.userDB1
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_
Hibernate: insert into COMPTE (NOM_COMPTE, NOM_BANQUE, SOLDE_INITIAL, ID_COMPTE) values (?, ?, ?, ?)
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_
tout cela me laisse perplexe

merci d'avance