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 package com.project.beans; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; @Entity public class Produit { @Id @GeneratedValue private int idProduit; private String codeProduit; private String description; private Type type; private double prix; public Produit() { } public Produit( String codeProduit, String description, Type type, double prix ) { this.codeProduit = codeProduit; this.description = description; this.type = type; this.prix = prix; } public String getCodeProduit() { return codeProduit; } public void setCodeProduit( String codeProduit ) { this.codeProduit = codeProduit; } public String getDescription() { return description; } public void setDescription( String description ) { this.description = description; } public Type getType() { return type; } public void setType( Type type ) { this.type = type; } public double getPrix() { return prix; } public void setPrix( double prix ) { this.prix = prix; } public int getIdProduit() { return idProduit; } }
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 package com.project.beans; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @Entity public class Type { @Id @GeneratedValue private int idType; private String libelle; public Type(){ } public Type(String libelle) { this.libelle = libelle; } public String getLibelle() { return libelle; } public void setLibelle(String libelle) { this.libelle = libelle; } public int getIdType() { return idType; } }
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 <?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> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/WMS</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <mapping class="com.project.beans.Produit"/> <mapping class="com.project.beans.Type"/> </session-factory> </hibernate-configuration>voici l'erreur genere:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public class test { public static void main( String[] args ) { ProduitService ps = new ProduitService(); Type type = new Type( "Equipement Informatique" ); ps.create( new Produit( "P1", "ASUS", type, 18000 ) ); ps.create( new Produit( "P2", "MSI", type, 8000 ) ); } }
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: com.project.beans.Produit, at table: Commande, for columns: [org.hibernate.mapping.Column(produit)]
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.project.util.HibernateUtil.<clinit>(HibernateUtil.java:18)
at com.project.service.ProduitService.create(ProduitService.java:19)
at com.project.test.test.main(test.java:16)
Caused by: org.hibernate.MappingException: Could not determine type for: com.project.beans.Produit, at table: Commande, for columns: [org.hibernate.mapping.Column(produit)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310)
at org.hibernate.mapping.Property.isValid(Property.java:241)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496)
at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1360)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
at com.project.util.HibernateUtil.<clinit>(HibernateUtil.java:14)
merci d'avance
Partager