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 :

Hibernate problème configuration


Sujet :

Hibernate Java

  1. #1
    Membre du Club
    Inscrit en
    Mars 2007
    Messages
    100
    Détails du profil
    Informations personnelles :
    Âge : 43

    Informations forums :
    Inscription : Mars 2007
    Messages : 100
    Points : 55
    Points
    55
    Par défaut Hibernate problème configuration
    Salut, j'ai un petit problème avec hibernate et je demande votre aide et merci d'avance.


    J'ai crée mon hibernate-config et les fichier de mapping avec hibernate sichronizer et tout est bien passéet c'est pour ça que j'ai crée une classe de test pour voir si tout marche très bien donc mon config est
    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
     
     
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration
        PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
     
    <hibernate-configuration>
        <session-factory >
     
    		<!-- local connection properties -->
    		<property name="hibernate.connection.url">jdbc:mysql://localhost:3309/cyruscp</property>
    		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    		<property name="hibernate.connection.username">root</property>
    		<property name="hibernate.connection.password">admin</property>
    		<!-- property name="hibernate.connection.pool_size"></property -->
     
    		<!-- dialect for MySQL -->
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
     
            <property name="hibernate.show_sql">false</property>
            <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
            <mapping resource="Adresse.hbm" />
    		<mapping resource="Banque.hbm" />
    		<mapping resource="Compte.hbm" />
    		<mapping resource="Coordonnee.hbm" />
    		<mapping resource="Devise.hbm" />
        </session-factory>
    </hibernate-configuration>

    le code que je teste avec est simple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    package TestHib;
     
     
    import java.util.List;
     
    public class RunTest {
    	public static void main(String[] arg){
         com.dao.AdresseDAO adr = new  com.dao.AdresseDAO();
         List lst = adr.findAll();
     
     
    }
    }
    l'erreur que j'ai c'est

    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
     
    INFO: Configuration resource: 
    15 août 2008 10:53:28 org.hibernate.util.XMLHelper$ErrorLogger error
    GRAVE: Error parsing XML: (1) Content is not allowed in prolog.
    Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: 
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1376)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
    	at com.base._BaseRootDAO.initialize(_BaseRootDAO.java:104)
    	at com.base._BaseRootDAO.initialize(_BaseRootDAO.java:88)
    	at com.base._BaseRootDAO.getSessionFactory(_BaseRootDAO.java:145)
    	at com.base._BaseRootDAO.getSession(_BaseRootDAO.java:64)
    	at com.base._BaseRootDAO.getSession(_BaseRootDAO.java:42)
    	at com.base._BaseRootDAO.findAll(_BaseRootDAO.java:259)
    	at com.base.BaseAdresseDAO.findAll(BaseAdresseDAO.java:82)
    	at TestHib.RunTest.main(RunTest.java:11)
    Caused by: org.dom4j.DocumentException: Error on line 1 of document  : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
    	at org.dom4j.io.SAXReader.read(SAXReader.java:355)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1366)
    	... 9 more
    j'ai pas compris et j'ai pas trouvé de solution merci de m'aider

  2. #2
    Membre chevronné Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Points : 2 232
    Points
    2 232
    Par défaut
    D'après la trace tu aurais une erreur à la première ligne de ton fichier de config. Tu ne dois pas avoir le droit de commencer par un espace ou un saut de ligne.

  3. #3
    Membre du Club
    Inscrit en
    Mars 2007
    Messages
    100
    Détails du profil
    Informations personnelles :
    Âge : 43

    Informations forums :
    Inscription : Mars 2007
    Messages : 100
    Points : 55
    Points
    55
    Par défaut
    Merci pour la réponse en fait ça n'arrive pas de là je pense car j'ai crée la classe HibernateUtil et ça donne ç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
     
    package TestHib;
     
     
    import java.util.List;
     
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
     
    public class RunTest {
    	public static void main(String[] arg){
    	Session  session = com.HibernateUtil.getSessionFactory().openSession();
         com.dao.AdresseDAO adr = new  com.dao.AdresseDAO(session);
       //  adr.setSession(session)
         List lst = adr.findAll();
     
     
    }
    }
    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
     
    <?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="com">
    	<class
    		name="Adresse"
    		table="adresse"
    	>
    		<meta attribute="sync-DAO">true</meta>
    		<id
    			name="Id"
    			type="integer"
    			column="id"
    		>
    			<generator class="vm"/>
    		</id>
     
    		<property
    			name="Destinataire"
    			column="destinataire"
    			type="string"
    			not-null="true"
    			length="10"
    		/>
    		<property
    			name="Numero"
    			column="numero"
    			type="string"
    			not-null="true"
    			length="10"
    		/>
    		<property
    			name="Voie"
    			column="voie"
    			type="string"
    			not-null="true"
    			length="10"
    		/>
    		<property
    			name="Complement"
    			column="complement"
    			type="string"
    			not-null="true"
    			length="10"
    		/>
    		<property
    			name="Etage"
    			column="etage"
    			type="string"
    			not-null="true"
    			length="10"
    		/>
    		<property
    			name="Escalier"
    			column="escalier"
    			type="string"
    			not-null="true"
    			length="10"
    		/>
    		<property
    			name="Batiment"
    			column="batiment"
    			type="string"
    			not-null="true"
    			length="10"
    		/>
    		<property
    			name="Ville"
    			column="ville"
    			type="string"
    			not-null="true"
    			length="10"
    		/>
    		<property
    			name="CodePostal"
    			column="codePostal"
    			type="string"
    			not-null="true"
    			length="10"
    		/>
    		<many-to-one
    			name="IdPays"
    			column="idPays"
    			class="Pays"
    			not-null="true"
    		>
    		</many-to-one>
    		<many-to-one
    			name="IdCoordonnee"
    			column="idCoordonnee"
    			class="Coordonnee"
    			not-null="true"
    		>
    		</many-to-one>
     
     
    		<set name="Socfactorings" inverse="true">
    			<key column="id"/>
    			<one-to-many class="Socfactoring"/>
    		</set>
     
    		<set name="Banques" inverse="true">
    			<key column="id"/>
    			<one-to-many class="Banque"/>
    		</set>
     
     
    	</class>	
    </hibernate-mapping>
    Une nouvelle erreur
    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
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
     
    15 août 2008 11:58:52 org.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 3.1.2
    15 août 2008 11:58:52 org.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    15 août 2008 11:58:52 org.hibernate.cfg.Environment <clinit>
    INFO: using CGLIB reflection optimizer
    15 août 2008 11:58:52 org.hibernate.cfg.Environment <clinit>
    INFO: using JDK 1.4 java.sql.Timestamp handling
    15 août 2008 11:58:52 org.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    15 août 2008 11:58:52 org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    15 août 2008 11:58:53 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource: Adresse.hbm
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: com.Adresse -> adresse
    15 août 2008 11:58:53 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource: Banque.hbm
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: com.Banque -> banque
    15 août 2008 11:58:53 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource: Compte.hbm
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: com.Compte -> compte
    15 août 2008 11:58:53 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource: Coordonnee.hbm
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: com.Coordonnee -> coordonnee
    15 août 2008 11:58:53 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource: Devise.hbm
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: com.Devise -> devise
    15 août 2008 11:58:53 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource: Socfactoring.hbm
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: com.Socfactoring -> socfactoring
    15 août 2008 11:58:53 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource: Pays.hbm
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: com.Pays -> pays
    15 août 2008 11:58:53 org.hibernate.cfg.Configuration doConfigure
    INFO: Configured SessionFactory: null
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
    INFO: Mapping collection: com.Adresse.Socfactorings -> socfactoring
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
    INFO: Mapping collection: com.Adresse.Banques -> banque
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
    INFO: Mapping collection: com.Banque.Comptes -> compte
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
    INFO: Mapping collection: com.Coordonnee.Adresses -> adresse
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
    INFO: Mapping collection: com.Devise.Comptes -> compte
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
    INFO: Mapping collection: com.Socfactoring.Comptes -> compte
    15 août 2008 11:58:53 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
    INFO: Mapping collection: com.Pays.Adresses -> adresse
    15 août 2008 11:58:53 org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Using Hibernate built-in connection pool (not for production use!)
    15 août 2008 11:58:53 org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Hibernate connection pool size: 20
    15 août 2008 11:58:53 org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: autocommit mode: false
    15 août 2008 11:58:53 org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3309/cyruscp
    15 août 2008 11:58:53 org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: connection properties: {user=root, password=****}
    15 août 2008 11:58:53 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: RDBMS: MySQL, version: 5.0.51b-community-nt
    15 août 2008 11:58:53 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.5 ( $Date: 2007-03-01 00:01:06 +0100 (Thu, 01 Mar 2007) $, $Revision: 6329 $ )
    15 août 2008 11:58:54 org.hibernate.dialect.Dialect <init>
    INFO: Using dialect: org.hibernate.dialect.MySQLDialect
    15 août 2008 11:58:54 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
    INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
    15 août 2008 11:58:54 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic flush during beforeCompletion(): disabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic session close at end of transaction: disabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC batch size: 15
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC batch updates for versioned data: disabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Scrollable result sets: enabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC3 getGeneratedKeys(): enabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Connection release mode: auto
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Maximum outer join fetch depth: 2
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default batch fetch size: 1
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Generate SQL with comments: disabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Order SQL updates by primary key: disabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
    INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    15 août 2008 11:58:54 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
    INFO: Using ASTQueryTranslatorFactory
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Second-level cache: enabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query cache: disabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory createCacheProvider
    INFO: Cache provider: org.hibernate.cache.EhCacheProvider
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Optimize cache for minimal puts: disabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Structured second-level cache entries: disabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Statistics: disabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Deleted entity synthetic identifier rollback: disabled
    15 août 2008 11:58:54 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default entity-mode: pojo
    15 août 2008 11:58:54 org.hibernate.impl.SessionFactoryImpl <init>
    INFO: building session factory
    15 août 2008 11:58:54 net.sf.ehcache.config.Configurator configure
    ATTENTION: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/bao/workspace/Hibernate%20test/WebContent/WEB-INF/lib/ehcache-0.9.jar!/ehcache-failsafe.xml
    Initial SessionFactory creation failed.org.hibernate.MappingException: could not instantiate id generator
    Exception in thread "main" java.lang.ExceptionInInitializerError
    	at com.HibernateUtil.<clinit>(HibernateUtil.java:16)
    	at TestHib.RunTest.main(RunTest.java:11)
    Caused by: org.hibernate.MappingException: could not instantiate id generator
    	at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:97)
    	at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
    	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:181)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
    	at com.HibernateUtil.<clinit>(HibernateUtil.java:12)
    	... 1 more
    Caused by: org.hibernate.MappingException: could not interpret id generator strategy: vm
    	at org.hibernate.id.IdentifierGeneratorFactory.getIdentifierGeneratorClass(IdentifierGeneratorFactory.java:108)
    	at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:91)
    	... 5 more

    comme tu vois c'est ici le problème could not instantiate id generator

  4. #4
    Membre chevronné Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Points : 2 232
    Points
    2 232
    Par défaut
    Le problème viebnt de ton fichier de mapping
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    			<generator class="vm"/>
    vm devrait être une classe ou un des mots clés réservé mais il ne fait partie d'aucun de ceux que j'ai pu trouver.

  5. #5
    Membre du Club
    Inscrit en
    Mars 2007
    Messages
    100
    Détails du profil
    Informations personnelles :
    Âge : 43

    Informations forums :
    Inscription : Mars 2007
    Messages : 100
    Points : 55
    Points
    55
    Par défaut
    Oui c'est vrai que le problème arrive de cette class mais le problème c'est que ça marche très bien avec Hibernate 2. avec le générateur hibernate synchronizer.
    et de quoi je dois changer ça ? j'ai essayé increment, assigned et toujours le même problème

Discussions similaires

  1. [Data] Problème configuration datasource hibernate
    Par Clezio dans le forum Spring
    Réponses: 3
    Dernier message: 26/07/2011, 20h56
  2. Réponses: 3
    Dernier message: 24/03/2010, 14h57
  3. Réponses: 10
    Dernier message: 25/02/2009, 16h34
  4. Problème Configuration Hibernate-Eclipse
    Par salirose dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 02/04/2008, 23h58
  5. [ Hibernate ] Problème de configuration. A l'aide !
    Par n@n¤u dans le forum Hibernate
    Réponses: 1
    Dernier message: 24/05/2006, 18h54

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