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 - Spring] Could not configure datastore from input stream ?


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 163
    Par défaut [Hibernate - Spring] Could not configure datastore from input stream ?
    J'ai fait une chtite appli utilisant Hibernate, j'ai voulu y intégrer Spring, mais
    j'ai une erreur dont je ne vois pas la cause :
    (sûrement un truc con, mais ça m'énerve !!! )

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HibernateUtil' defined in file [D:\Utilisat\a432566\Mes Documents\Workspace\HibernateOmegaPersonne2mergeSpring\src\hibernate.spring.xml]: Cannot resolve reference to bean 'SessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SessionFactory' defined in file [D:\Utilisat\a432566\Mes Documents\Workspace\HibernateOmegaPersonne2mergeSpring\src\hibernate.spring.xml]: Initialization of bean failed; nested exception is net.sf.hibernate.MappingException: org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SessionFactory' defined in file [D:\Utilisat\a432566\Mes Documents\Workspace\HibernateOmegaPersonne2mergeSpring\src\hibernate.spring.xml]: Initialization of bean failed; nested exception is net.sf.hibernate.MappingException: org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net
    net.sf.hibernate.MappingException: org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net
     
    ...
    16:11:47,268 ERROR Configuration:295 - Could not configure datastore from input stream
    Mon fichier de config Spring :
    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
    <beans>
     
      <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="url" value="XXX"/>
        <property name="username" value="XXX"/>
        <property name="password" value="XXX"/>
      </bean>
     
      <bean id="SessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
        <property name="dataSource" ref="myDataSource"/>
        <property name="mappingResources">
          <list>
            <value>unidirectionnel/mappings/personne.hbm.xml</value>
            <value>unidirectionnel/mappings/telephone.hbm.xml</value>
          </list>
        </property>
        <property name="hibernateProperties">
          <props>
            <prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
          </props>
        </property>
      </bean>
     
      <bean id="HibernateUtil" class="util.HibernateUtil">
        <property name="sessionFactory" ref="SessionFactory"/>
      </bean>
     
    </beans>
    Appel dans l'appli :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    BeanFactory factory = new XmlBeanFactory(new FileSystemResource("src/hibernate.spring.xml"));
    			gs=(HibernateUtil)factory.getBean("HibernateUtil"); //Plante ici !!!! :(
    			s = gs.getCurrentSession();

  2. #2
    Membre confirmé Avatar de nikalkal
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    231
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2004
    Messages : 231
    Par défaut
    fais voir ta classe HibernateUtil, il ne doit pas y avoir de SessionFactory dans celle-çi.

    Je cherche un exemple que j'ais déja posté sur le forum et je te mets le lien plus tard.

    @+

  3. #3
    Membre confirmé Avatar de nikalkal
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    231
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2004
    Messages : 231
    Par défaut
    Ok regarde dans ce post : http://www.developpez.net/forums/sho...d.php?t=136071
    le message 2 et plus particulièrement la classe HibernateUserServiceImp qui possède une SessionFactory.

    Ps: je n'utilise pas la classe HibernateUtil (inutile avec hibernate3).

    Je pense que si tu creuse un peu ce modèle tu devrais t'en sortir.
    C'était mon 1er bout de code avec struts+hibernate+spring et il tourne bien.

    Ps2: si tu as du mal à comprendre le fonctionnement et les relations entre mes classes, tu peux aussi regarder ce post : http://www.developpez.net/forums/sho...d.php?t=136904

    Bon courage , tiens moi au courant.
    @+

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 163
    Par défaut HibernateUtil
    Voici HibernateUtil :

    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
    package util;
     
    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
     
    public class HibernateUtil {
     
    	private SessionFactory sessionFactory=null;
     
    	public final ThreadLocal session = new ThreadLocal();
     
    	public Session getCurrentSession() throws HibernateException {
    		Session s = (Session) session.get();
    		// Ouvre une nouvelle Session, si ce Thread n'en a aucune
    		if (s == null) {
    			s = sessionFactory.openSession();
    			session.set(s);
    		}
    		return s;
    	}
     
    	public void closeSession() throws HibernateException {
    		Session s = (Session) session.get();
    		session.set(null);
    		if (s != null)
    			s.close();
    	}
     
    	/**
             * @return SessionFactory donne la session factory
             */
    	public SessionFactory getSessionFactory() {
    		return this.sessionFactory;
    	}
     
    	/**
             * @param laSessionFactory setter de liaison Spring
             */
    	public void setSessionFactory(SessionFactory laSessionFactory) {
    		this.sessionFactory = laSessionFactory;
    	}
    Merci.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 163
    Par défaut A suivre...
    Jregarde tes liens ! Merci.

  6. #6
    Membre confirmé Avatar de nikalkal
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    231
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2004
    Messages : 231
    Par défaut
    Ok je ne vois pas trop ce qui cloche, on a une petite différence dans nos déclarations :
    <property name="sessionFactory" ref="SessionFactory"/> et
    <property name="sessionFactory"><ref local="mySessionFactory"/></property>
    mais bon je ne sais pas si ca change grand chose....

    En fait en re-regardant la trace, le problème est : Error creating bean with name 'SessionFactory' ce qui veut dire que c'est là qu'il y a le problème.

    l'exception étant net.sf.hibernate.MappingException... es-tu sur de l'existance des fichiers
    unidirectionnel/mappings/personne.hbm.xml
    unidirectionnel/mappings/telephone.hbm.xml
    et de la validité de ces chemins?

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 163
    Par défaut
    Disons, que quand je lance mon test avec la version 3, il trouve bien les mappings :

    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
    11:49:34,936  INFO Environment:479 - Hibernate 3.1.2
    11:49:34,946  INFO Environment:509 - hibernate.properties not found
    11:49:34,946  INFO Environment:525 - using CGLIB reflection optimizer
    11:49:34,946  INFO Environment:555 - using JDK 1.4 java.sql.Timestamp handling
    11:49:35,367  INFO HbmBinder:309 - Mapping class: unidirectionnel.bean.Personne -> PERSONNE
    11:49:35,477  INFO HbmBinder:309 - Mapping class: unidirectionnel.bean.Telephone -> TELEPHONE
    11:49:35,477  INFO HbmBinder:2349 - Mapping collection: unidirectionnel.bean.Personne.telephones -> TELEPHONE
    11:49:35,848  INFO ConnectionProviderFactory:72 - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
    11:49:36,428  INFO SettingsFactory:77 - RDBMS: Oracle, version: Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    11:49:36,428  INFO SettingsFactory:78 - JDBC driver: Oracle JDBC driver, version: 9.0.1.1.0
    11:49:36,448  INFO Dialect:103 - Using dialect: org.hibernate.dialect.Oracle9Dialect
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HibernateUtil' defined in file [D:\Utilisat\a432566\Mes Documents\Workspace\HibernateOmegaPersonne3mergeSpring\src\hibernate.spring.xml]: Cannot resolve reference to bean 'SessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SessionFactory' defined in file [D:\Utilisat\a432566\Mes Documents\Workspace\HibernateOmegaPersonne3mergeSpring\src\hibernate.spring.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SessionFactory' defined in file [D:\Utilisat\a432566\Mes Documents\Workspace\HibernateOmegaPersonne3mergeSpring\src\hibernate.spring.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
    java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
    	at java.lang.Class.getDeclaredConstructors0(Native Method)
    	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2328)
    	at java.lang.Class.getConstructor0(Class.java:2640)
    	at java.lang.Class.newInstance0(Class.java:321)
    	at java.lang.Class.newInstance(Class.java:303)
    	at org.hibernate.cfg.SettingsFactory.createCacheProvider(SettingsFactory.java:327)
    	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:219)
    	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:825)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:751)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1091)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:396)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1046)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
    	at unidirectionnel.mappings.TestUni.actionAffichage(TestUni.java:221)
    	at unidirectionnel.mappings.TestUni.main(TestUni.java:116)
    Exception in thread "main" java.lang.NullPointerException
    	at unidirectionnel.mappings.TestUni.actionAffichage(TestUni.java:239)
    	at unidirectionnel.mappings.TestUni.main(TestUni.java:116)
    11:49:36,458  INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
    11:49:36,458  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    11:49:36,468  INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled
    11:49:36,468  INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
    11:49:36,478  INFO SettingsFactory:136 - JDBC batch size: 15
    11:49:36,478  INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled
    11:49:36,478  INFO SettingsFactory:144 - Scrollable result sets: enabled
    11:49:36,478  INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled
    11:49:36,478  INFO SettingsFactory:160 - Connection release mode: on_close
    11:49:36,478  INFO SettingsFactory:187 - Default batch fetch size: 1
    11:49:36,478  INFO SettingsFactory:191 - Generate SQL with comments: disabled
    11:49:36,478  INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
    11:49:36,478  INFO SettingsFactory:338 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    11:49:36,478  INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
    11:49:36,478  INFO SettingsFactory:203 - Query language substitutions: {}
    11:49:36,488  INFO SettingsFactory:209 - Second-level cache: enabled
    11:49:36,488  INFO SettingsFactory:213 - Query cache: disabled
    11:49:36,488  INFO SettingsFactory:325 - Cache provider: org.hibernate.cache.EhCacheProvider
    J'ai rajouté local, ça ne change rien ! Même problème
    J'ai aussi essayé d'enlever HibernateUtil, lors d'un test d'une version sans Spring, mais il plante quand j'fée mon s = sf.getCurrentSession(); Car sf est à null apparemment, mais où l'instancier?

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 09/08/2012, 13h54
  2. Réponses: 1
    Dernier message: 28/12/2010, 11h08
  3. Réponses: 1
    Dernier message: 14/02/2009, 09h12
  4. [Hibernate][error] Could not execute JDBC batch update
    Par CPI_en_mousse dans le forum Hibernate
    Réponses: 7
    Dernier message: 01/06/2007, 09h41
  5. [Hibernate] : Erreur Could not find datasource
    Par tipaquo dans le forum Hibernate
    Réponses: 2
    Dernier message: 12/10/2005, 10h43

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