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 :

Problème accés aux POJO


Sujet :

Hibernate Java

  1. #1
    Membre du Club
    Inscrit en
    Juin 2004
    Messages
    143
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 143
    Points : 56
    Points
    56
    Par défaut Problème accés aux POJO
    Bonjour,

    J'ai beau retourner le problème dans tous les sens, rien à faire :

    J'ai une exception lors du dépoiement de monj appli ou dedans il y a
    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
     
    java.lang.ExceptionInInitializerError
    	at mgpat.datawarehouse.jdbc.ServiceHibernate.requeteUniqueObject(ServiceHibernate.java:45)
    	at mgpat.authentification.ServiceAuthentification.authentification(ServiceAuthentification.java:33)
    	at mgpat.authentification.EcompteAdhEtAdminTest.testSoumettre(EcompteAdhEtAdminTest.java:13)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:585)
    	at junit.framework.TestCase.runTest(TestCase.java:154)
    	at junit.framework.TestCase.runBare(TestCase.java:127)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: java.lang.RuntimeException: 
    	*** EXCEPTION ***
     
    		-- Exception levée depuis [mgpat.datawarehouse.jdbc.HibernateUtil.creationSessionFactory()]
    	at mgpat.datawarehouse.jdbc.HibernateUtil.<clinit>(HibernateUtil.java:32)
    	... 21 more
    Caused by: org.hibernate.MappingException: Association references unmapped class: mgpat.espaceadherent.adherent.hibernate.Decompte
    	at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2344)
    	at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2618)
    	at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:35)
    	at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1012)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1168)
    	at mgpat.datawarehouse.jdbc.HibernateUtil.<clinit>(HibernateUtil.java:29)
    	... 21 more
    C'est normal, puique ma classe Decompte n'est pas dans ce package :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    mgpat.espaceadherent.adherent.hibernate
    mais dans mgpat.espaceadherent.presta.hibernate.Decompte comme je l'ai bien défini le bon mapping dans mon hibernate.cfg.xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <mapping resource="mgpat/espaceadherent/presta/hibernate/Decompte.hbm.xml"/>
    et j'ai alloué ma relation comme suis dans le fichier des personnes :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <!--  Relation entre le décompte et les actes -->
    		 <set name="decomptes" lazy="false">
    		 	<key column="idpersonne" />
    		 	<one-to-many class="Decompte" />
    		 </set>
    Mon POJO étant bien la classe décompte.

    Je bloque total, une idée ?

  2. #2
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    Si le pojo n'est pas dans le même fichier de mapping, renseigne le nom de classe complète de Décompte dans ta relation One-to-many.

    Ainsi tu aurais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <!--  Relation entre le décompte et les actes -->
    <set name="decomptes" lazy="false">
    	<key column="idpersonne" />
    	<one-to-many class="mgpat.espaceadherent.adherent.hibernate.Decompte" />
    </set>
    Ca ira mieux ainsi

    Bon courage
    See you, space cowboy... and if you're satisfied, click on

  3. #3
    Membre du Club
    Inscrit en
    Juin 2004
    Messages
    143
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 143
    Points : 56
    Points
    56
    Par défaut
    si si mon Pojo est dans le même fichier de mapping :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <mapping resource="mgpat/authentification/EcompteAdh.hbm.xml"/>
    		<mapping resource="mgpat/authentification/EcompteAdmin.hbm.xml"/>
    		<mapping resource="mgpat/espaceadherent/adherent/hibernate/Personne.hbm.xml"/>
    		<mapping resource="mgpat/espaceadherent/adherent/hibernate/Rib.hbm.xml"/>
    		<mapping resource="mgpat/espaceadherent/adherent/hibernate/Groupe.hbm.xml"/>
    		<mapping resource="mgpat/espaceadherent/adherent/hibernate/ContratClient.hbm.xml"/>
    		<mapping resource="mgpat/espaceadherent/presta/hibernate/Decompte.hbm.xml"/>
    		<mapping resource="mgpat/espaceadherent/presta/hibernate/Acte.hbm.xml"/>
    J'ai bien Personne et Decompte dans le même fichier de mapping. Mais les deux classes ne sont pas dans le même package effectivement.
    Je pensais qu'avec le fichier de mapping, il ferait le lien automatiquement.

  4. #4
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    Quand je parlais de fichier de mapiping je parlais réellement de fichier physique.
    Là tu me signales qu'ils sont tous deux dans la même configuration de Session Factory certes (c'est bien normal sinon cherche pas, ca ne fonctionnerait jamais ), mais on voit bien un fichier physique Decompte.hbm.xml et un autre fichier Personne.hbm.xml.

    D'où la problématique... Hibernate n'accepte "Decompte " dans personne que si les deux objets sont situés dans le même fichier physique de mapping voire dans le même package également (avec l'attribut package rempli dans le tag hibernate-mapping). Si le cas ne se présente pas, préfère afficher le nom complet (et dans un sens, c'est tout de même beaucoup plus lisible de toujours mettre le nom complet pour éviter d'éventuelle ambiguité
    See you, space cowboy... and if you're satisfied, click on

  5. #5
    Membre du Club
    Inscrit en
    Juin 2004
    Messages
    143
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 143
    Points : 56
    Points
    56
    Par défaut
    Ok, je comprend la démarche !
    Merci

  6. #6
    Membre du Club
    Inscrit en
    Juin 2004
    Messages
    143
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 143
    Points : 56
    Points
    56
    Par défaut
    Bon ca marche cependant j'ai une autre exception

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    [mgpat.datawarehouse.jdbc.HibernateUtil.creationSessionFactory()]
    	at mgpat.datawarehouse.jdbc.HibernateUtil.<clinit>(HibernateUtil.java:32)
    	... 21 more
    Caused by: org.hibernate.MappingException: Could not determine type for: String, for columns: [org.hibernate.mapping.Column(tiers)]
    	at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
    	at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
    	at org.hibernate.mapping.Property.isValid(Property.java:185)
    	at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:395)
    	at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
    	at org.hibernate.cfg.Configuration.validate(Configuration.java:984)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
    	at mgpat.datawarehouse.jdbc.HibernateUtil.<clinit>(HibernateUtil.java:29)
    	... 21 more

  7. #7
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    Tu peux mettre le desc de table et le fichier de mapping correspondant ?
    See you, space cowboy... and if you're satisfied, click on

  8. #8
    Membre du Club
    Inscrit en
    Juin 2004
    Messages
    143
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 143
    Points : 56
    Points
    56
    Par défaut
    Arf erreur de jeunnesse, par contre je sèche sur un truc :

    J'ai plusieur hbm, plusieur classe ...
    Je compile mon code, le test en local grâce à des classes de tests et tout est ok !

    Lorsque je déploie mon appli sous jboss j'ai l'exception suivante que je ne cerne pas trop :

    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
     
    *** EXCEPTION ***
     
    		-- Exception levée depuis [mgpat.datawarehouse.jdbc.HibernateUtil.creationSessionFactory()]
    	at mgpat.datawarehouse.jdbc.HibernateUtil.<clinit>(HibernateUtil.java:32)
    	... 34 more
    Caused by: org.hibernate.MappingException: Could not read mappings from resource: mgpat/espaceadherent/adherent/hibernate/Personne.hbm.xml
    	at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
    	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
    	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
    	at mgpat.datawarehouse.jdbc.HibernateUtil.<clinit>(HibernateUtil.java:29)
    	... 34 more
    Caused by: org.hibernate.MappingException: class mgpat.espaceadherent.adherent.hibernate.Personne not found while looking for property: rib
    	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:80)
    	at org.hibernate.mapping.ToOne.setTypeUsingReflection(ToOne.java:58)
    	at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2138)
    	at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2115)
    	at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2005)
    	at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:368)
    	at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282)
    	at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
    	at org.hibernate.cfg.Configuration.add(Configuration.java:386)
    	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
    	at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
    	... 41 more
    Caused by: java.lang.: mgpat.espaceadherent.adherent.hibernate.Personne
    	at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:198)
    	at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:475)
    	at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:377)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:164)
    	at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
    	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:76)
    	... 51 more

  9. #9
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    arf, rien pour moi non plus, par contre petite question, quelle est ta base de données utilisée ? character varying, ca ne me parle pas trop , j'ai plus l'habitude de VARCHAR
    Si tu enleves cet attribut, cela passe ou tu bloque sur un autre champ du même type ?!?
    See you, space cowboy... and if you're satisfied, click on

  10. #10
    Membre du Club
    Inscrit en
    Juin 2004
    Messages
    143
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 143
    Points : 56
    Points
    56
    Par défaut
    ma faute
    Par contre j'ai modifié le l'erreur au dessus ma trompé quand j ai posé ma question

  11. #11
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    OK, donc bah la ca semble "évident" à analyser, il ne parvient pas à lire le fichier de mapping de ta Personne. Reste à résoudre ce problème :

    -Erreur de parsing du fichier XML ?
    -Location not found ?
    Du coup, Personne n'est pas mappée et il ne le trouve pas en cherchant le rib.
    -Peut-on voir le rib en question ?!? C'est un autre objet mappé ?
    See you, space cowboy... and if you're satisfied, click on

  12. #12
    Membre du Club
    Inscrit en
    Juin 2004
    Messages
    143
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 143
    Points : 56
    Points
    56
    Par défaut
    Oui c'est un autre objet mappé !

    Par contre la récupération des ribs marche trés bien en test !

    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
     
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
     
    <hibernate-mapping package="mgpat.espaceadherent.adherent.hibernate">
    	<class name="Rib" table="rib">
    		<id name="idrib" type="integer">
    			<generator class="native" />
    		</id>
     
    		<property
    			column="numversement"
    			length="255"
    			name="numversement"
    			type="string"
    		 />
     
    		<property
    			column="numpaiement"
    			length="255"
    			name="numpaiement"
    			type="string"
    		 />
     
    		 <property
    			column="numadherent"
    			length="15"
    			name="numadherent"
    			type="string"
    		 />
     
    		  <property
    			column="coderang"
    			name="coderang"
    			type="integer"
    		 />
    	</class>	
    </hibernate-mapping>

  13. #13
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    Hum, étrange, pourquoi en lisant Rib il ne trouve pas Personne ?
    Petite question, le numadherent est-il un simple int ou bien un objet Personne ?!? Car la ca semble étrange qu'il doive piocher dans Personne à partir de rib O_o
    See you, space cowboy... and if you're satisfied, click on

  14. #14
    Membre du Club
    Inscrit en
    Juin 2004
    Messages
    143
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 143
    Points : 56
    Points
    56
    Par défaut
    un simple String dans mon objet Rib

  15. #15
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    Et le rapport avec la personne ?!? La personne possède un Rib c'est bien ca ? Alors va voir de ce coté si, par hasard, il n'y aurait pas une erreur non ?!?
    See you, space cowboy... and if you're satisfied, click on

Discussions similaires

  1. BufferedImage et accès plus direct aux pixels
    Par millie dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 09/01/2010, 10h40
  2. [XL-2003] Accès protégé conditionnel aux feuilles d'un même fichier
    Par rberniga dans le forum Excel
    Réponses: 3
    Dernier message: 28/08/2009, 12h06
  3. Réponses: 11
    Dernier message: 28/07/2009, 10h10
  4. Avantage des EJB par rapport aux POJO
    Par Baptiste Wicht dans le forum JPA
    Réponses: 6
    Dernier message: 13/03/2008, 10h58
  5. Accès des Applications aux fichiers de config
    Par TryExceptEnd dans le forum Windows XP
    Réponses: 5
    Dernier message: 09/10/2007, 14h45

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