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 :

Heritage :Exeption : org.hibernate.MappingException: Could not determine type for:


Sujet :

Hibernate Java

  1. #1
    Inactif
    Inscrit en
    Mars 2005
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 42
    Points : 31
    Points
    31
    Par défaut Problème de subclass
    Bonjour a tous,
    voila mon probleme :

    j'essaie de faire mon appli hibernate avec l heritage mais ca me sort cette exeption :

    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
    Exception in thread "main" org.hibernate.WrongClassException: Object with id: 55 was not of the specified subclass: appHIB.LienFichier (loaded object was of wrong class class appHIB.LienDossier)
    	at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:1243)
    	at org.hibernate.loader.Loader.getRow(Loader.java:1195)
    	at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
    	at org.hibernate.loader.Loader.doQuery(Loader.java:701)
    	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    	at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
    	at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
    	at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
    	at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
    	at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
    	at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
    	at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:844)
    	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:241)
    	at org.hibernate.loader.Loader.doList(Loader.java:2213)
    	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    	at org.hibernate.loader.Loader.list(Loader.java:2099)
    	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    	at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    	at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    	at appHIB.DossierDAO.ShearchDossier(DossierDAO.java:73)
    	at appHIB.Exec.main(Exec.java:51)
    voila mon hbm :
    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
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
     
     
    <hibernate-mapping package="appHIB">
    	<class name="FileSystem" table="fileSystem">
     
     
    		<id name="id" type="long" column="id">
    			<generator class="native">
     
    			</generator>
    		</id>
     
    		<discriminator column="sousclasse" type="java.lang.String" />
    		<property name="nom" column="nom" length="20" />
    		<property name="dateCreation" column="dateCreation" length="20" />
    		<property name="dateModification" column="dateModification"
    			length="20" />
    		<many-to-one name="pere" lazy="false" class="Dossier"
    			column="idparent" />
    		<property name="root" column="isRoot" length="20" />
     
     
    		<subclass name="Dossier" discriminator-value="D">
    			<set name="dossiers" inverse="false" lazy="false" cascade="all">
    				<key column="idparent" />
    				<one-to-many class="Dossier" />
    			</set>
    			<set name="fichiers" inverse="false" lazy="false" cascade="all">
    				<key column="idparent" />
    				<one-to-many class="Fichier" />
    			</set>
    			<set name="lienFichiers" inverse="false" lazy="false" cascade="all">
    				<key column="idparent" />
    				<one-to-many class="LienFichier" />
    			</set>
    			<set name="LienDossiers" inverse="false" lazy="false" cascade="all">
    				<key column="idparent" />
    				<one-to-many class="LienDossier" />
    			</set>
    		</subclass>
     
     
     
    		<subclass name="Fichier" discriminator-value="F">
    			<property name="type" column="type" length="20" />
    		</subclass>
     
     
    		<subclass name="LienFichier" discriminator-value="L">
    			<property name="link" column="idlink" type="long" length="20" />
    		</subclass>
     
     
    		<subclass name="LienDossier" discriminator-value="M">
    			<property name="link" column="idlink" type="long" length="20" />
    		</subclass>
    	</class>
    </hibernate-mapping>
    voila mes classs :
    FileSystem:
    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
     
    package appHIB ;
     
    import java.util.Date;
     
    public class FileSystem  {
    	private Long id ; 
    	private String nom ;
    	private Date dateCreation ;
    	private Date  dateModification ;
    	private Dossier pere ;
    	private boolean isRoot;
    	private String sousClass ;
     
     
    	public FileSystem() {
    		this.id = null ;
    		this.pere = null ;
    		this.nom = null ;
    		this.dateCreation = null ;
    		this.dateModification = null ;
    		this.isRoot = false ;
    		this.sousClass = null ;
     
        }
     
        public FileSystem(Long id, Dossier pere, String nom, Date dateCreation, Date dateModification,boolean isRoot , String sousClass) {
        	this.id = null ;
    		this.pere = pere ;
    		this.nom = nom ;
    		this.dateCreation = dateCreation ;
    		this.dateModification = dateModification ;
    		this.isRoot = isRoot ;
    		this.sousClass = sousClass ;
        }
     
        void   setId (Long id) { this.id = id ;}
        public Long   getId () {return id ;}
     
     
        public Dossier getPere() {return pere;}
    	public void setPere(Dossier pere) {this.pere = pere;}
     
    	public String getNom() {return nom;}
    	public void setNom(String nom) {this.nom = nom;}
     
    	public Date getDateCreation() {return dateCreation;}
    	public void setDateCreation(Date dateCreation) {
    		this.dateCreation = dateCreation;
    	}
     
    	public Date getDateModification() {return dateModification;}
    	public void setDateModification(Date dateModification) {
    		this.dateModification = dateModification;
    	}
     
    	public boolean isRoot() {	return isRoot;	}
    	public void setRoot(boolean isRoot) {this.isRoot = isRoot;}
     
     
    	public String getSousClass() {return sousClass;	}
    	public void setSousClass(String sousClass) {
    		this.sousClass = sousClass;	}
     
     
     
    }
    Dossier.java:
    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
     
     
    package appHIB ;
     
    import java.util.Date;
    import java.util.Set;
     
    public class Dossier  extends FileSystem{
     
    	private Set<Dossier> dossiers;
    	private Set<Fichier> fichiers;
    	private Set<LienDossier> lienDossiers;
    	private Set<LienFichier> lienFichiers;
     
    	public Dossier() {
    		super();
    		this.dossiers = null ;
    		this.fichiers = null ;
    		this.lienDossiers = null ;
    		this.lienFichiers = null ;
        }
     
        public Dossier(Long id, Dossier pere, String nom, Date dateCreation, 
        		Date dateModification,Set<Dossier> dossiers, Set<Fichier> fichiers,
        		Set<LienDossier> lienDossiers, Set<LienFichier> lienFichiers,
        		boolean isRoot ,String sousClass) {
        	super( id,  pere,  nom,  dateCreation,  dateModification, isRoot ,sousClass);
        	this.dossiers = dossiers ;
    		this.fichiers = fichiers ;
    		this.lienDossiers = lienDossiers ;
    		this.lienFichiers = lienFichiers ;
        }
     
    	public Set<Dossier> getDossiers() {return dossiers;}
    	public void setDossiers(Set<Dossier> dossiers){this.dossiers = dossiers;}
     
    	public Set<Fichier> getFichiers() {return fichiers;}
    	public void setFichiers(Set<Fichier> fichiers){this.fichiers = fichiers;}
     
    	public Set<LienDossier> getLienDossiers() {	return lienDossiers;}
    	public void setLienDossiers(Set<LienDossier> lienDossiers){this.lienDossiers = lienDossiers;}
     
    	public Set<LienFichier> getLienFichiers() {return lienFichiers;}
    	public void setLienFichiers(Set<LienFichier> lienFichiers) {this.lienFichiers = lienFichiers;}
    }
    Fichier:
    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
     
     
    package appHIB ;
     
    import java.util.Date;
     
    public class Fichier extends FileSystem {
     
    	String type;
     
     
    	public Fichier() {
    		super();
    		this.type = null;
        }
     
        public Fichier(Long id, Dossier pere, String nom, Date dateCreation, Date dateModification,
        		String type , boolean isRoot ,String sousClass) {
        	super( id,  pere,  nom,  dateCreation,  dateModification, isRoot ,sousClass);
        	this.type = type;
        }
     
        public String getType() {
    		return type;
    	}
     
    	public void setType(String type) {
    		this.type = type;
    	}
    }
    LienDossier:
    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
     
    package appHIB ;
     
    import java.util.Date;
     
    public class LienDossier extends FileSystem  {
     
    	Dossier link ;
     
     
    	public LienDossier() {
    		super();
            link = null;
        }
     
        public LienDossier(Long id, Dossier pere, String nom, Date dateCreation, 
        		Date dateModification, Dossier link) {
        	super( id,  pere,  nom,  dateCreation,  dateModification);
            this.link = link;
        }
     
    	public Dossier getLink() {
    		return link;
    	}
     
    	public void setLink(Dossier link) {
    		this.link = link;
    	}
     
     
     
    }
    LienFichier:
    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
     
    package appHIB ;
     
    import java.util.Date;
     
    public class LienFichier extends FileSystem  {
     
    	Fichier link ;
     
     
    	public LienFichier() {
    		super();
            link = null;
        }
     
        public LienFichier(Long id, Dossier pere, String nom, Date dateCreation, 
        		Date dateModification, Fichier link) {
        	super( id,  pere,  nom,  dateCreation,  dateModification);
            this.link = link;
        }
     
        public Fichier getLink() {
    		return link;
    	}
     
    	public void setLink(Fichier link) {
    		this.link = link;
    	}
     
     
     
    }
    voila mon main que j execute:
    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
    	public static void main(String[] args)
    		throws HibernateException, ParseException {
    		 System.out.println("1");
    		 /*********              test               ***********/
     
     
    		 Session session = HibernateUtil.getSessionFactory().openSession(); 
    	     Transaction tx = session.beginTransaction();
     
    	     DossierDAO doaDossier = new DossierDAO();
    	     FichierDAO doaFichier = new FichierDAO();
     
    	     //Dossier pere
    	     Dossier dossier0 = doaDossier.ajouter(null,"/",  
    	    		 null, 
    	    		 null,null ,null, true ,
    	    		 "D",session);
     
    	   //Dossier pere
    //	     ajouter(Dossier pere,String nom, boolean isRoot ,
    //	    		 String sousClass,String type, Session session) 
     
    	     Fichier fichier1 = doaFichier.ajouter(dossier0,"fichier1",  
    	    		  false ,
    	    		 "F","binaire",session);
    	     Fichier fichier2 = doaFichier.ajouter(dossier0,"fichier2",  
    	    		  false ,
    	    		 "F","binaire",session);
    	     Long id =dossier0.getId();
    	     tx.commit();
    	     session.close();
     
    	     Session session1 = HibernateUtil.getSessionFactory().openSession(); 
    	     dossier0 = doaDossier.ShearchDossier(dossier0.getId(), session1);
    	     for(Fichier fihierRecup : dossier0.getFichiers()){
    	    	 System.out.println("fihierRecup " +fihierRecup);
    	     }
     
     
    	     session1.close();

    niveau BD J'ai une table fileSystem qui contient tous les attribus mappé


    merci de m aider

  2. #2
    Inactif
    Inscrit en
    Mars 2005
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 42
    Points : 31
    Points
    31
    Par défaut
    merci de m aider

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 8
    Dernier message: 13/08/2014, 17h42
  2. Erreur "Could not determine type for"
    Par maroonet dans le forum Hibernate
    Réponses: 7
    Dernier message: 29/11/2011, 10h01
  3. Could not determine type for: java.util.Set
    Par poitou82 dans le forum Hibernate
    Réponses: 1
    Dernier message: 05/07/2011, 11h53
  4. Réponses: 1
    Dernier message: 01/04/2009, 15h41
  5. Réponses: 1
    Dernier message: 14/02/2009, 09h12

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