Bonjour,
J'ai décidé de suivre une auto formation sur le JEE et j'ai commencé par un tuto "JPA par l'exemple"
http://tahe.developpez.com/java/jpa/
il explique pas à pas comment réaliser des applications. il met à disposition tous les projets java de test. j'ai suivi toutes les configurations (installation de tous les composants tel MySQL, eclipse + les plugins)
pré-problème : mon eclipse plante à chaque manipulation après l'installation des plugins
problème : "quand eclipse survis à une manipulation ou exécution"
l'exemple crée
- la classe java "Personne" que l'on veut persister avec les annotations nécessaires
- le fichier XML de mapping ici "persistance.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
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 package entites; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Version; @SuppressWarnings("unused") @Entity @Table(name="jpa01_personne") public class Personne { @Id @Column(name = "ID", nullable = false) @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @Column(name = "VERSION", nullable = false) @Version private int version; @Column(name = "NOM", length = 30, nullable = false, unique = true) private String nom; @Column(name = "PRENOM", length = 30, nullable = false) private String prenom; @Column(name = "DATENAISSANCE", nullable = false) @Temporal(TemporalType.DATE) private Date datenaissance; @Column(name = "MARIE", nullable = false) private boolean marie; @Column(name = "NBENFANTS", nullable = false) private int nbenfants; // constructeurs public Personne() { } public Personne(String nom, String prenom, Date datenaissance, boolean marie, int nbenfants) { setNom(nom); setPrenom(prenom); setDatenaissance(datenaissance); setMarie(marie); setNbenfants(nbenfants); } // toString public String toString() { return String.format("[%d,%d,%s,%s,%s,%s,%d]", getId(), getVersion(), getNom(), getPrenom(), new SimpleDateFormat("dd/MM/yyyy") .format(getDatenaissance()), isMarie(), getNbenfants()); } // getters and setters public Integer getId() { return id; } private void setId(Integer id) { this.id = id; } public int getVersion() { return version; } private void setVersion(int version) { this.version = version; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } public Date getDatenaissance() { return datenaissance; } public void setDatenaissance(Date datenaissance) { this.datenaissance = datenaissance; } public boolean isMarie() { return marie; } public void setMarie(boolean marie) { this.marie = marie; } public int getNbenfants() { return nbenfants; } public void setNbenfants(int nbenfants) { this.nbenfants = nbenfants; } }
- le fichier ant. Quand j'exécute ce dernier, le programme s'arrête à la tache DDL et ne passe a la création de la table PERSONNE.
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 <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL"> <!-- provider --> <provider>org.hibernate.ejb.HibernatePersistence</provider> <properties> <!-- Classes persistantes --> <property name="hibernate.archive.autodetection" value="class, hbm" /> <!-- logs SQL <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="use_sql_comments" value="true"/> --> <!-- connexion JDBC --> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jpa" /> <property name="hibernate.connection.username" value="jpa" /> <property name="hibernate.connection.password" value="jpa" /> <!-- création automatique du schéma --> <property name="hibernate.hbm2ddl.auto" value="create" /> <!-- Dialecte --> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> <!-- propriétés DataSource c3p0 --> <property name="hibernate.c3p0.min_size" value="5" /> <property name="hibernate.c3p0.max_size" value="20" /> <property name="hibernate.c3p0.timeout" value="300" /> <property name="hibernate.c3p0.max_statements" value="50" /> <property name="hibernate.c3p0.idle_test_period" value="3000" /> </properties> </persistence-unit> </persistence>
le résultat que j'obtient :
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 <project name="jpa-hibernate" default="compile" basedir="."> <!-- nom du projet et version --> <property name="proj.name" value="jpa-hibernate" /> <property name="proj.shortname" value="jpa-hibernate" /> <property name="version" value="1.0" /> <!-- Propriété globales --> <property name="src.java.dir" value="src" /> <property name="lib.dir" value="../../../lib" /> <property name="build.dir" value="bin" /> <!-- le Classpath du projet --> <path id="project.classpath"> <fileset dir="${lib.dir}"> <include name="**/*.jar" /> </fileset> </path> <!-- les fichiers de configuration qui doivent être dans le classpath--> <patternset id="conf"> <include name="**/*.xml" /> <include name="**/*.properties" /> </patternset> <!-- Nettoyage projet --> <target name="clean" description="Nettoyer le projet"> <delete dir="${build.dir}" /> <mkdir dir="${build.dir}" /> </target> <!-- Compilation projet --> <target name="compile" depends="clean"> <javac srcdir="${src.java.dir}" destdir="${build.dir}" classpathref="project.classpath" /> </target> <!-- Copier les fichiers de configuration dans le classpath --> <target name="copyconf"> <mkdir dir="${build.dir}" /> <copy todir="${build.dir}"> <fileset dir="${src.java.dir}"> <patternset refid="conf" /> </fileset> </copy> </target> <!-- Hibernate Tools --> <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.classpath" /> <!-- Générer le schéma de la base --> <target name="DDL" depends="compile, copyconf" description="Génération DDL base"> <hibernatetool destdir="${basedir}"> <classpath path="${build.dir}" /> <!-- Utiliser META-INF/persistence.xml --> <jpaconfiguration /> <!-- export --> <hbm2ddl drop="true" create="true" export="false" outputfilename="ddl/schema.sql" delimiter=";" format="true" /> </hibernatetool> </target> <!-- Générer la base --> <target name="BD" depends="compile, copyconf" description="Génération BD"> <hibernatetool destdir="${basedir}"> <classpath path="${build.dir}" /> <!-- Utiliser META-INF/persistence.xml --> <jpaconfiguration /> <!-- export --> <hbm2ddl drop="true" create="true" export="true" outputfilename="ddl/schema.sql" delimiter=";" format="true" /> </hibernatetool> </target> </project>
DDL:
[hibernatetool] Executing Hibernate Tool with a JPA Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
BUILD SUCCESSFUL
Total time: 9 seconds
le resultat qu'il faut obtenir :
DDL:
10. [hibernatetool] Executing Hibernate Tool with a JPA Configuration
11. [hibernatetool] 1. task: hbm2ddl (Generates database schema)
12. [hibernatetool] drop table if exists jpa01_personne;
13. [hibernatetool] create table jpa01_personne (
14. [hibernatetool] ID integer not null auto_increment,
15. [hibernatetool] VERSION integer not null,
16. [hibernatetool] NOM varchar(30) not null unique,
17. [hibernatetool] PRENOM varchar(30) not null,
18. [hibernatetool] DATENAISSANCE date not null,
19. [hibernatetool] MARIE bit not null,
20. [hibernatetool] NBENFANTS integer not null,
21. [hibernatetool] primary key (ID)
22. [hibernatetool] ) ENGINE=InnoDB;
23. BUILD SUCCESSFUL
24. Total time: 5 seconds
j'ai vérifié la base de donnée tout est bon. Le plugin SQLExplorer me confirma que mon eclipse a bien accès à la base. çà fait 2 jours que je suis planté là dessus.
le projet en question est en pièce jointe
Merci pour votre aide
Configuration
Win XP Pro
eclipse Helios + Hibernate tools + SQLExplorer + Connector MySQL
BDD : MySQL 5.1 + MySQL Administarator
j'ai intallé les dernière mise a jour de tous les composant précédemment mentionnés
Partager