Bonjour,
J'ai repris un vieux code pour hibernate 4 et je l'ai modifié pour passer à la version 5
Je fais ma configuration par le code.
Je ne comprends pas la stack
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95 public class TestConfiguration implements AutoCloseable { private static Logger logger = Logger.getLogger("Log"); private static SessionFactory sessionFactory; public TestConfiguration() { } public void open() { if (sessionFactory == null) { try { Configuration configuration = new Configuration(); // Parametres de la base de donnees configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); configuration.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver"); configuration.setProperty("hibernate.connection.url", "jdbc:hsqldb:file:local/test.hsql"); configuration.setProperty("hibernate.connection.username", "sa"); configuration.setProperty("hibernate.connection.password", ""); configuration.setProperty("hibernate.connection.pool_size", "10"); configuration.setProperty("hibernate.connection.autocommit", "true"); configuration.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider"); configuration.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory"); configuration.setProperty("hibernate.hbm2ddl.auto", "update"); // configuration.setProperty("hibernate.hbm2ddl.auto","create-drop"); configuration.setProperty("connection.show_sql", "true"); // Parametres de session configuration.setProperty("hibernate.current_session_context_class", "thread"); // Ajout des classes annotées configuration.addAnnotatedClass(Classe.class); configuration.addAnnotatedClass(Compte.class); configuration.addAnnotatedClass(Journal.class); // configuration.addAnnotatedClass(Mouvement.class); // configuration.addAnnotatedClass(Ecriture.class); // configuration.addAnnotatedClass(EcritureDeBrouillard.class); // configuration.addAnnotatedClass(EcritureValidee.class); // configuration.addAnnotatedClass(Lettrage.class); // configuration.addAnnotatedClass(Solde.class); sessionFactory = configuration.buildSessionFactory(); } catch (MappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (HibernateException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void close() { sessionFactory.close(); } public SessionFactory getSessionFactory() { if (sessionFactory == null) { open(); } return sessionFactory; } public Session getSession() { if (sessionFactory == null) { open(); } return sessionFactory.openSession(); } public static void main(String[] args) { try (TestConfiguration config = new TestConfiguration()) { config.open(); Session session = config.getSession(); StringBuilder requete = new StringBuilder(); requete.append("from Compte order by numero"); Query query = session.createQuery(requete.toString()); ArrayList<Compte> comptes = (ArrayList<Compte>) query.list(); System.out.println("Size : " + comptes.size()); for (Compte compte : comptes) { System.out.println(compte); } } catch (Exception e) { e.printStackTrace(); } } }
Je pense avoir bien tout renseigné
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 log4j:WARN No appenders could be found for logger (org.jboss.logging). log4j:WARN Please initialize the log4j system properly. log4j:WARN See <a href="http://logging.apache.org/log4j/1.2/faq.html#noconfig" target="_blank">http://logging.apache.org/log4j/1.2/faq.html#noconfig</a> for more info. org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:122) at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140) at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58) at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178) at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928) at TestConfiguration.open(TestConfiguration.java:58) at TestConfiguration.main(TestConfiguration.java:92) Caused by: java.sql.SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@1c267c20[file =D:\Dropbox\Eclipse\workspaces\EasyComptaJ2E\ComptaDAO\local\test.hsql.lck, exists=true, locked=false, valid=false, ] method: checkHeartbeat read: 2018-03-18 15:13:24 heartbeat - read: -6654 ms. at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source) at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source) at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source) at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55) ... 15 more Caused by: org.hsqldb.HsqlException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@1c267c20[file =D:\Dropbox\Eclipse\workspaces\EasyComptaJ2E\ComptaDAO\local\test.hsql.lck, exists=true, locked=false, valid=false, ] method: checkHeartbeat read: 2018-03-18 15:13:24 heartbeat - read: -6654 ms. at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.persist.LockFile.newLockFileLock(Unknown Source) at org.hsqldb.persist.Logger.acquireLock(Unknown Source) at org.hsqldb.persist.Logger.open(Unknown Source) at org.hsqldb.Database.reopen(Unknown Source) at org.hsqldb.Database.open(Unknown Source) at org.hsqldb.DatabaseManager.getDatabase(Unknown Source) at org.hsqldb.DatabaseManager.newSession(Unknown Source) ... 19 more org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
Cordialement
Fabrice
Partager