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] - Création auto des tables des modèles


Sujet :

Hibernate Java

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 44
    Par défaut [Hibernate] - Création auto des tables des modèles
    Bonjour,

    Je suis face à un problème que je n'arrive pas à résoudre. J'utilise Hibernate avec les notations @Table, @Entity, @Id ...

    J'ai une application à plusieurs datasources. Le problème est que lorsque je load une datasource il me crée toutes les tables respectives de tous les modèles de l'application.

    J'aimerais cependant que ce ne soit pas le cas. Je n'ai pas trouvé l'option d'hibernate à ajouter pour ne pas avoir la création automatique.


    J'espère avoir été clair , quelqu'un sait il comment y remédier?

    Merci d'avance

    Ride

  2. #2
    Membre éprouvé Avatar de we.are.the.storm
    Profil pro
    Inscrit en
    Février 2009
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 115
    Par défaut
    Bonjour,

    Il suffit de ne pas renseigner la property hibernate.hbm2ddl.auto (commenter la ligne).

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 44
    Par défaut
    Merci de ta réponse rapide

    Je suis dans le cas ou hibernate et couplé avec spring. J'ai pas d'option hbm2dll.

    J'ai donc paramétrer de cette manière:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    <property name="jpaVendorAdapter">
    	        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    	           <property name="showSql" value="true" />
    	           <property name="generateDdl" value="true" />
    	           <property name="hibernate.hbm2ddl.auto" value="update" />
    	           <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
    	        </bean>
    	     </property>

    J'ai essayé les valeurs présentes dans la doc officielle sans succès

    Les tables se créent encore

  4. #4
    Membre éprouvé Avatar de we.are.the.storm
    Profil pro
    Inscrit en
    Février 2009
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 115
    Par défaut
    Retire ou commente la ligne suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <property name="hibernate.hbm2ddl.auto" value="update" />

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 44
    Par défaut
    Cela ne change rien. Il continue de créer les tables dans toutes les databases différentes.

  6. #6
    Membre éprouvé Avatar de we.are.the.storm
    Profil pro
    Inscrit en
    Février 2009
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 115
    Par défaut
    En mettant generateDdl à false ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <property name="generateDdl" value="false"  />

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 44
    Par défaut
    Eh bien non toujours pas :s, je ne sais pas trop d'où cela peut venir.

    Je rapelle que je suis couplé Struts, spring et hibernate.

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 44
    Par défaut
    Un petit up car je possède toujours le même soucis!

  9. #9
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 44
    Par défaut
    C'est la valeur de <property name="generateDdl" value="false" /> qui gere

    Environment.HBM2DDL_AUTO.

    D'après le site http://www.jdocs.com/spring/2.5.2/or...orAdapter.html

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    if (isGenerateDdl()) {
         jpaProperties.setProperty(Environment.HBM2DDL_AUTO, "update");
    }
    Cependant étant à False dans mon cas, je ne vois pas comment cela peut fonctionner?

  10. #10
    Membre averti
    Profil pro
    Inscrit en
    Février 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 44
    Par défaut
    Je poste à tout hasard le spring-context.xml

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:jee="http://www.springframework.org/schema/jee"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
     
     
    	<bean id="metaBoDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiName">
            	<value>java:comp/env/jdbc/metabackofficeAdmin</value>
        	</property>
    	</bean>
     
     
    	<!--  Entity Manager Factory : utilisation de JPA via son implémentation Hibernate 						 -->
    	<!--  On utilise le LocalContainerEntityManagerFactoryBean : 										     -->
    	<!--  voir http://static.springframework.org/spring/docs/2.0.x/reference/orm.html#orm-jpa-setup-lcemfb   -->
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
    		  <property name="jpaVendorAdapter">
    	        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    	           <property name="showSql" value="false" />
    	           <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
    	        </bean>
    	     </property>
    		<property name="dataSource" ref="metaBoDataSource" />
    	</bean>
     
    	<!-- Post-processor pour les annotations JPA                                                               -->
    	<!-- voir http://static.springframework.org/spring/docs/2.0.x/reference/orm.html#orm-jpa-straight          -->
    	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
     
    	<!--  Translation d'exception : Ce processeur permet, via l'ajout d'une annotation @Repository  sur les DAO -->
    	<!--  des faire la translation d'exceptions Spring                                                        -->
    	<!-- voir : http://static.springframework.org/spring/docs/2.0.x/reference/orm.html#orm-jpa-exceptions      -->
    	<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
     
     
    	<!--  Transaction manager -->
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    	    <property name="entityManagerFactory" ref="entityManagerFactory" />
    		<property name="dataSource" ref="metaBoDataSource" />
    	</bean>
     
    	<!--  Ce tag dit à Spring de gérer de manière transactionnelle les classes ou les méthodes qui ont         -->
    	<!-- l'annotation @Transactionnal (couche service)                                                         -->
    	<!-- voir : http://static.springframework.org/spring/docs/2.0.x/reference/transaction.html#transaction-declarative-annotations -->
    	<tx:annotation-driven />
     
    	<!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    	   <property name="dataSource" ref="metaBoDataSource" />
    	   <property name="hibernateProperties">
    	     <props>
    	       <prop key="hibernate.dialect">
    	         	org.hibernate.dialect.MySQLDialect
    	       </prop>
    	     </props>
    	   </property>>-->
    	   <!--  <property name="annotatedClasses">
    	     <list>
    	       <value>fr.sewatech.data.university.CourseData</value>
    	     </list>
    	   </property>-->
    	 <!--</bean>>
     
     
    	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
         <property name="sessionFactory" ref="sessionFactory" />
       </bean>-->
    </beans>
    Voici le frontControllerServelet-servelet.xml

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    	- Contexte d'application pour spring-mvc-webapp.
    -->
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    		xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
    		xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    				http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
     
    	<import resource="spring-context.xml"/>
     
    	<!-- DAO -->	
    	<bean id="ConfigurationFournisseurPaiementSecuriseDAO" class="fr.addonline.geniecommerce.metabackoffice.ui.persistence.jpa.ConfigurationFournisseurPaiementSecuriseDAOJPAImpl"/>
    	<bean id="ConfigurationSiteClientDAO" class="fr.addonline.geniecommerce.metabackoffice.ui.persistence.jpa.ConfigurationSiteClientDAOJPAImpl"/>
    	<bean id="ClientAjoutDAO" class="fr.addonline.geniecommerce.metabackoffice.ui.persistence.jpa.ClientAjoutDAOJPAImpl"/>
    	<bean id="ConfigurationAdminSiteClientDAO" class="fr.addonline.geniecommerce.metabackoffice.ui.persistence.jpa.ConfigurationAdminSiteClientDAOJPAImpl" />
    	<bean id="RecuperationListeClientGenieCommerceDAO" class="fr.addonline.geniecommerce.metabackoffice.ui.persistence.jpa.RecuperationListeClientGenieCommerceDAOJPAImpl" />
    	<bean id="ConfigurationApacheDAO" class="fr.addonline.geniecommerce.metabackoffice.ui.persistence.jpa.ConfigurationApacheDAOJPAImpl" />
    	<bean id="ClientDAO" class="fr.addonline.geniecommerce.metabackoffice.ui.persistence.jpa.ClientDAOJPAImpl"/>
    	<bean id="ConfigurationIncludesVhostsDAO" class="fr.addonline.geniecommerce.metabackoffice.ui.persistence.jpa.ConfigurationIncludesVhostsDAOJPAImpl"/>
    	<bean id="ConfigurationBindDAO" class="fr.addonline.geniecommerce.metabackoffice.ui.persistence.jpa.ConfigurationBindDAOJPAImpl" />
    	<bean id="ConfigurationModelJSPDAO" class="fr.addonline.geniecommerce.metabackoffice.ui.persistence.jpa.ConfigurationModelJSPDAOJPAImpl" />
    </beans>

Discussions similaires

  1. Création d'un id auto généré pour des tables différentes
    Par Invité dans le forum Développement de jobs
    Réponses: 1
    Dernier message: 29/08/2014, 14h42
  2. [XI R2 SP2 Deski] Création d'une table des matières
    Par alain.nico dans le forum Deski
    Réponses: 7
    Dernier message: 28/12/2007, 09h31
  3. Réponses: 4
    Dernier message: 04/06/2007, 11h04
  4. [DAO]Création d'un table des matières
    Par IDE dans le forum Word
    Réponses: 1
    Dernier message: 01/04/2007, 17h47
  5. [Hibernate] Comment ramener les valeurs des tables de ref ?
    Par PamelaGeek dans le forum Hibernate
    Réponses: 9
    Dernier message: 07/02/2006, 23h52

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