Bonjour,

Voilà que ça fait plusieurs jours que j'essaye de faire fonctionner Hibernate, mais j'ai toujours des problèmes.

J'ai lu la FAQ.

J'ai acheté le livre Hibernate 3.0 (Anthony Patricio)

J'ai lu le didacticiel fourni avec Hibernate.

Et j'ai toujours pas pu executer quoi que ce soit avec Hibernate.

J'ai un problème suivant :
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
.19:07:03,134  INFO Environment:514 - Hibernate 3.2.5
19:07:03,305  INFO Environment:532 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:mysql:///test, hibernate.show_sql=true, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
19:07:03,315  INFO Environment:563 - using java.io streams to persist binary types
19:07:03,325  INFO Environment:681 - Bytecode provider name : cglib
19:07:03,455  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
19:07:03,936  INFO Configuration:530 - Reading mappings from resource: cours3/model/Team.hbm.xml
19:07:04,396 DEBUG DTDEntityResolver:38 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
19:07:04,396 DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
19:07:04,406 DEBUG DTDEntityResolver:50 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
19:07:05,378  INFO HbmBinder:300 - Mapping class: cours3.model.Team -> TEAM
19:07:05,498 DEBUG HbmBinder:1270 - Mapped property: id -> TEAM_ID
19:07:05,568 DEBUG HbmBinder:1270 - Mapped property: name -> TEAM_NAME
19:07:05,568 DEBUG HbmBinder:1270 - Mapped property: nbWon -> NB_WON
19:07:05,578 DEBUG HbmBinder:1270 - Mapped property: nbLost -> NB_LOST
19:07:05,578 DEBUG HbmBinder:1270 - Mapped property: nbPlayed -> NB_PLAYED
19:07:06,079 DEBUG HbmBinder:1270 - Mapped property: coach -> COACH_ID
19:07:06,109 DEBUG HbmBinder:1270 - Mapped property: players
19:07:06,119 DEBUG HbmBinder:1270 - Mapped property: homeGames
19:07:06,129 DEBUG HbmBinder:1270 - Mapped property: awayGames
19:07:06,139  INFO Configuration:530 - Reading mappings from resource: cours3/model/Coach.hbm.xml
19:07:06,159 DEBUG DTDEntityResolver:38 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
19:07:06,159 DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
19:07:06,189 DEBUG DTDEntityResolver:50 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
19:07:06,449  INFO HbmBinder:300 - Mapping class: cours3.model.Coach -> COACH
19:07:06,459 DEBUG HbmBinder:1270 - Mapped property: id -> COACH_ID
19:07:06,469 DEBUG HbmBinder:1270 - Mapped property: name -> COACH_NAME
19:07:06,469  INFO Configuration:530 - Reading mappings from resource: cours3/model/Player.hbm.xml
19:07:06,479 DEBUG DTDEntityResolver:38 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
19:07:06,479 DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
19:07:06,489 DEBUG DTDEntityResolver:50 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
19:07:06,690  INFO HbmBinder:300 - Mapping class: cours3.model.Player -> PLAYER
19:07:06,700 DEBUG HbmBinder:1270 - Mapped property: id -> PLAYER_ID
19:07:06,700 DEBUG HbmBinder:1270 - Mapped property: name -> PLAYER_NAME
19:07:06,700 DEBUG HbmBinder:1270 - Mapped property: number -> PLAYER_NUMBER
19:07:06,710 DEBUG HbmBinder:1270 - Mapped property: birthday -> BIRTHDAY
19:07:06,710 DEBUG HbmBinder:1270 - Mapped property: height -> HEIGHT
19:07:06,710 DEBUG HbmBinder:1270 - Mapped property: weight -> WEIGHT
19:07:06,720 DEBUG HbmBinder:1270 - Mapped property: hasBeenMvpCount -> select count(*) from GAME g where g.PLAYER_ID = PLAYER_ID
19:07:06,720 DEBUG HbmBinder:1270 - Mapped property: team -> TEAM_ID
19:07:06,730  INFO Configuration:530 - Reading mappings from resource: cours3/model/Game.hbm.xml
19:07:06,740 DEBUG DTDEntityResolver:38 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
19:07:06,740 DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
19:07:06,750 DEBUG DTDEntityResolver:50 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
19:07:06,860  INFO HbmBinder:300 - Mapping class: cours3.model.Game -> GAME
19:07:06,880 DEBUG HbmBinder:1270 - Mapped property: id -> GAME_ID
19:07:06,910 DEBUG HbmBinder:1270 - Mapped property: awayTeamScore -> AWAY_TEAM_SCORE
19:07:06,920 DEBUG HbmBinder:1270 - Mapped property: homeTeamScore -> HOME_TEAM_SCORE
19:07:06,920 DEBUG HbmBinder:1270 - Mapped property: gameDate -> GAME_DATE
19:07:06,920 DEBUG HbmBinder:1270 - Mapped property: mostValuablePlayer -> PLAYER_ID
19:07:06,920 DEBUG HbmBinder:1270 - Mapped property: homeTeam -> HOME_TEAM_ID
19:07:06,930 DEBUG HbmBinder:1270 - Mapped property: awayTeam -> AWAY_TEAM_ID
19:07:07,100  INFO Dialect:152 - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
19:07:07,140 DEBUG Configuration:1285 - Preparing to build session factory with filters : {}
19:07:07,140 DEBUG Configuration:1120 - processing extends queue
19:07:07,140 DEBUG Configuration:1124 - processing collection mappings
19:07:07,140 DEBUG CollectionSecondPass:41 - Second pass for collection: cours3.model.Team.players
19:07:07,150  INFO HbmBinder:2385 - Mapping collection: cours3.model.Team.players -> PLAYER
19:07:07,150 DEBUG CollectionSecondPass:57 - Mapped collection key: TEAM_ID, one-to-many: cours3.model.Player
19:07:07,190 DEBUG CollectionSecondPass:41 - Second pass for collection: cours3.model.Team.homeGames
19:07:07,190  INFO HbmBinder:2385 - Mapping collection: cours3.model.Team.homeGames -> GAME
19:07:07,200 DEBUG CollectionSecondPass:57 - Mapped collection key: HOME_TEAM_ID, index: GAME_DATE, one-to-many: cours3.model.Game
19:07:07,200 DEBUG CollectionSecondPass:41 - Second pass for collection: cours3.model.Team.awayGames
19:07:07,200  INFO HbmBinder:2385 - Mapping collection: cours3.model.Team.awayGames -> GAME
19:07:07,210 DEBUG CollectionSecondPass:57 - Mapped collection key: AWAY_TEAM_ID, index: GAME_DATE, one-to-many: cours3.model.Game
19:07:07,210 DEBUG Configuration:1135 - processing native query and ResultSetMapping mappings
19:07:07,210 DEBUG Configuration:1143 - processing association property references
19:07:07,210 DEBUG Configuration:1165 - processing foreign key constraints
19:07:07,210 DEBUG Configuration:1248 - resolving reference to class: cours3.model.Team
19:07:07,210 DEBUG Configuration:1248 - resolving reference to class: cours3.model.Team
19:07:07,220 DEBUG Configuration:1248 - resolving reference to class: cours3.model.Player
19:07:07,220 DEBUG Configuration:1248 - resolving reference to class: cours3.model.Team
19:07:07,220 DEBUG Configuration:1248 - resolving reference to class: cours3.model.Coach
19:07:07,270  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
19:07:07,280  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
19:07:07,280  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
19:07:07,371  INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql:///test
19:07:07,381  INFO DriverManagerConnectionProvider:83 - connection properties: {user=root, password=root}
19:07:07,381 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
19:07:07,381 DEBUG DriverManagerConnectionProvider:109 - opening new JDBC connection
19:07:13,239 DEBUG DriverManagerConnectionProvider:115 - created connection to: jdbc:mysql:///test, Isolation Level: 4
19:07:13,249  INFO SettingsFactory:89 - RDBMS: MySQL, version: 5.0.37-community-nt
19:07:13,249  INFO SettingsFactory:90 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.5 ( Revision: ${svn.Revision} )
19:07:13,249 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
19:07:13,269  INFO Dialect:152 - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
19:07:13,299  INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
19:07:13,319  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
19:07:13,319  INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
19:07:13,319  INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
19:07:13,329  INFO SettingsFactory:162 - Scrollable result sets: enabled
19:07:13,329 DEBUG SettingsFactory:166 - Wrap result sets: disabled
19:07:13,329  INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): enabled
19:07:13,329  INFO SettingsFactory:178 - Connection release mode: auto
19:07:13,329  INFO SettingsFactory:202 - Maximum outer join fetch depth: 1
19:07:13,339  INFO SettingsFactory:205 - Default batch fetch size: 1
19:07:13,339  INFO SettingsFactory:209 - Generate SQL with comments: disabled
19:07:13,339  INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
19:07:13,349  INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
19:07:13,389  INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
19:07:13,409  INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
19:07:13,409  INFO SettingsFactory:225 - Query language substitutions: {no='N', true=1, yes='Y', false=0}
19:07:13,419  INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
19:07:13,419  INFO SettingsFactory:235 - Second-level cache: enabled
19:07:13,419  INFO SettingsFactory:239 - Query cache: enabled
19:07:13,419  INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.EhCacheProvider
19:07:13,519  INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
19:07:13,519  INFO SettingsFactory:259 - Cache region prefix: hibernate.test
19:07:13,529  INFO SettingsFactory:263 - Structured second-level cache entries: disabled
19:07:13,529  INFO SettingsFactory:360 - Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
19:07:13,610 DEBUG SQLExceptionConverterFactory:52 - Using dialect defined converter
19:07:13,640  INFO SettingsFactory:283 - Echoing all SQL to stdout
19:07:13,680  INFO SettingsFactory:290 - Statistics: disabled
19:07:13,680  INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
19:07:13,680  INFO SettingsFactory:309 - Default entity-mode: pojo
19:07:13,680  INFO SettingsFactory:313 - Named query checking : enabled
19:07:14,090  INFO SessionFactoryImpl:161 - building session factory
19:07:14,090 DEBUG SessionFactoryImpl:173 - Session factory constructed with filter configurations : {}
19:07:14,110 DEBUG SessionFactoryImpl:177 - instantiating session factory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=root, hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider, sun.boot.library.path=C:\Program Files\Java\jre1.5.0\bin, java.vm.version=1.5.0-b64, hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, hibernate.cache.use_query_cache=true, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=FR, sun.os.patch.level=Service Pack 2, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate, java.runtime.version=1.5.0-b64, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Program Files\Java\jre1.5.0\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\RUS\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, hibernate.jdbc.batch_versioned_data=true, hibernate.cache.region_prefix=hibernate.test, sun.jnu.encoding=Cp1251, java.library.path=C:\Program Files\Java\jre1.5.0\bin;.;C:\WINDOWS\system32;C:\WINDOWS;c:\Program Files\PHP\;C:\Program Files\Java\jdk1.5.0\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;;, java.specification.name=Java Platform API Specification, java.class.version=49.0, hibernate.connection.pool_size=1, sun.management.compiler=HotSpot Client Compiler, os.version=5.1, user.home=C:\Documents and Settings\RUS, user.timezone=Europe/Paris, java.awt.printerjob=sun.awt.windows.WPrinterJob, java.specification.version=1.5, file.encoding=Cp1252, hibernate.connection.driver_class=com.mysql.jdbc.Driver, user.name=RUS, java.class.path=C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\bin;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\c3p0-0.8.4.5.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\cglib-full-2.0.2.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\commons-beanutils.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\commons-collections-2.1.1.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\commons-digester.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\commons-logging-1.0.4.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\connector.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\dom4j-1.5.2.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\ehcache-1.1.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\hsqldb.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\jaas.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\jakarta-oro.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\jdbc2_0-stdext.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\jta.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\junit-3.8.1.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\log4j-1.2.9.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\odmg-3.0.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\ant-antlr-1.6.2.jar;C:\TRAVAIL\formation\JAVA\Hibenate\TransfertHibernate\lib\antlr-2.7.4.jar;C:\TRAVAIL\formation\eclipse\workspace\hibernate-3.0;C:\hibernate\lib\hibernate3.jar;C:\hibernate\lib\mysql-connector-java-5.1.5-bin.jar;C:\hibernate\lib\hibernate3.jar, hibernate.bytecode.use_reflection_optimizer=false, hibernate.show_sql=true, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', java.vm.specification.version=1.0, sun.arch.data.model=32, java.home=C:\Program Files\Java\jre1.5.0, hibernate.connection.url=jdbc:mysql:///test, hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect, java.specification.vendor=Sun Microsystems Inc., user.language=fr, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, java.version=1.5.0, hibernate.jdbc.use_streams_for_binary=true, java.ext.dirs=C:\Program Files\Java\jre1.5.0\lib\ext, sun.boot.class.path=C:\Program Files\Java\jre1.5.0\lib\rt.jar;C:\Program Files\Java\jre1.5.0\lib\i18n.jar;C:\Program Files\Java\jre1.5.0\lib\sunrsasign.jar;C:\Program Files\Java\jre1.5.0\lib\jsse.jar;C:\Program Files\Java\jre1.5.0\lib\jce.jar;C:\Program Files\Java\jre1.5.0\lib\charsets.jar;C:\Program Files\Java\jre1.5.0\classes, java.vendor=Sun Microsystems Inc., hibernate.jdbc.batch_size=0, file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, hibernate.hbm2ddl.auto=create-drop, sun.cpu.endian=little, sun.io.unicode.encoding=UnicodeLittle, sun.desktop=windows, hibernate.max_fetch_depth=1, sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86}
E
Time: 11,907
There was 1 error:
1) testFormula(cours2.test.FormulaTest)java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProvider
	at org.hibernate.cache.EhCacheProvider.start(EhCacheProvider.java:124)
	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:183)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
	at test.TestCase.buildSessionFactory(TestCase.java:86)
	at test.TestCase.setUp(TestCase.java:102)
	at cours2.test.FormulaTest.main(FormulaTest.java:44)
 
FAILURES!!!
Tests run: 1,  Failures: 0,  Errors: 1
Les exemples des classes sont pris dans le livre
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
package cours2.test;
 
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
 
import org.hibernate.Session;
import org.hibernate.Transaction;
 
import cours3.model.Player;
 
/**
 * @author Anthony
 *
 * Simple formula test 
 */
public class FormulaTest extends TestCaseWithData{
 
 
	public void testFormula() throws Exception  {
		initData();
		Session session = openSession();
		Transaction tx = null ;
		tx = session.beginTransaction();
		Player player = (Player)session.get(Player.class, new Long(1));
		assertEquals(player.getHasBeenMvpCount(),1);
		tx.commit();
		session.close();
	}
 
	public FormulaTest(String arg0) {
		super(arg0);
	}
 
	public String[] getMappings() {
		return new String[] {"cours3/model/Team.hbm.xml","cours3/model/Coach.hbm.xml","cours3/model/Player.hbm.xml","cours3/model/Game.hbm.xml" };
	}
 
	public static Test suite() {
		return new TestSuite(FormulaTest.class);
	}
 
	public static void main(String[] args) throws Exception {
		TestRunner.run( suite() );
	}
}
J'ai essayé de faire fonctionner sous Eclipse, j'ai rajouté tous les JARs nécessaires.

Ma BD est MySQL qui tourne très bien avec les scripts PHP sur ma machine.




Pourquoi ça marche pas