IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

org hibernate MappingException


Sujet :

Hibernate Java

  1. #1
    Invité
    Invité(e)
    Par défaut org hibernate MappingException
    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>
    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 ) );
     
        }
     
    }
    voici l'erreur genere:

    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

  2. #2
    Invité
    Invité(e)
    Par défaut
    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
    package com.project.beans;
     
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Inheritance;
    import javax.persistence.InheritanceType;
     
    @Entity
    @Inheritance( strategy = InheritanceType.TABLE_PER_CLASS )
    public class Commande {
        @Id
        @GeneratedValue( strategy = GenerationType.TABLE )
        private int     idCommande;
        private Produit produit;
        private int     quantite;
        private String  date;
        private String  etat;
        private boolean priseEnChargeLiv;
     
        public Commande() {
        }
     
        public Commande( Produit produit, int quantite, String date, String etat, boolean priseEnChargeLiv ) {
            this.produit = produit;
            this.quantite = quantite;
            this.date = date;
            this.etat = etat;
            this.priseEnChargeLiv = priseEnChargeLiv;
        }
     
        public Produit getProduit() {
            return produit;
        }
     
        public void setProduit( Produit produit ) {
            this.produit = produit;
        }
     
        public int getQuantite() {
            return quantite;
        }
     
        public void setQuantite( int quantite ) {
            this.quantite = quantite;
        }
     
        public String getDate() {
            return date;
        }
     
        public void setDate( String date ) {
            this.date = date;
        }
     
        public String getEtat() {
            return etat;
        }
     
        public void setEtat( String etat ) {
            this.etat = etat;
        }
     
        public boolean isPriseEnChargeLiv() {
            return priseEnChargeLiv;
        }
     
        public void setPriseEnChargeLiv( boolean priseEnChargeLiv ) {
            this.priseEnChargeLiv = priseEnChargeLiv;
        }
     
        public int getIdCommande() {
            return idCommande;
        }
     
    }

Discussions similaires

  1. Réponses: 1
    Dernier message: 12/03/2009, 11h51
  2. Réponses: 1
    Dernier message: 24/02/2009, 19h18
  3. Réponses: 8
    Dernier message: 17/04/2008, 17h29
  4. premier exemple hibernate: org.hibernate.MappingException
    Par info_plus dans le forum Hibernate
    Réponses: 3
    Dernier message: 26/03/2008, 12h31
  5. Réponses: 3
    Dernier message: 09/10/2006, 14h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo