-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: [Résolu]Génération des tables avec hbm2ddl.auto incomplè
PostPosted: Mon Aug 21, 2006 11:57 am 
Newbie

Joined: Mon Aug 21, 2006 8:33 am
Posts: 2
Bonjour,
J'ai un problème avec la génération atomatique des tables dans ma base Mysql (version 4.1.20) J'utilise hibernate 3.0.3

J'active dans hibernate.cfg.xml hbm2ddl.auto.
Cela me crée bien les tables USER, USER_INTERESTS, INTERESTS, COMMUNITY, COMMUNITY_INTERESTS mais ne me crée aucunement la table USER_COMMUNITIES.

Je ne vois pas où cela peut-être, j'ai mis à jour mes versions de mysql et hibernate (je travaille sous gentoo) donc si vous avez une idée voire une solution sans pourtant créer un schéma sql à la main.

Merci.

hibernate.cfg.xml

Code:
<hibernate-configuration>
<session-factory>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>

<property name="dbcp.defaultAutoCommit">false</property>
<property name="dbcp.maxActive">50</property>
<property name="dbcp.maxIdle">5</property>
<property name="dbcp.maxWait">30000</property>
<property name="dbcp.whenExhaustedAction">1</property>
<property name="dbcp.ps.whenExhaustedAction">1</property>
<property name="dbcp.ps.maxActive">20</property>
<property name="dbcp.ps.maxWait">120000</property>
<property name="dbcp.ps.maxIdle">20</property>

<property name="connection.url">jdbc:mysql://localhost/xwiki</property>
<property name="connection.username">xwiki</property>
<property name="connection.password">xwiki</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<property name="connection.pool_size">50</property>
<property name="statement_cache.size">50</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hbm2ddl.auto">update</property>
    <!-- Mapping files -->
<mapping resource="community.hbm.xml"/>
<mapping resource="interest.hbm.xml"/>
<mapping resource="user.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Voici les mappings des classes

UserClass

Code:
<hibernate-mapping auto-import="true">
    <class name="com.rcg.bn.UserClass" table="USER">
        <id name="NickName" type="string" unsaved-value="any">
               <column name="USER_NICK" not-null="true"/>
               <generator class="assigned" />
           </id>

           <property name="FirstName" type="string">
               <column name="USER_FIRST" length="255" not-null="true"/>
            </property>
           <property name="LastName" type="string">
               <column name="USER_LAST" length="255" not-null="true"/>
            </property>
           <property name="Gender" type="string">
               <column name="USER_GENDER" length="255" not-null="true"/>
            </property>
           <property name="YearOfBirth" type="int">
               <column name="USER_YEARBIRTH" length="255" not-null="false"/>
            </property>
           <property name="PlaceOfBirth" type="string">
               <column name="USER_PLACEBIRTH" length="255" not-null="false"/>
            </property>
           <property name="City" type="string">
               <column name="USER_CITY" not-null="true"/>
            </property>
           <property name="Country" type="string">
               <column name="USER_COUNTRY" not-null="true"/>
            </property>
           <property name="Mobile" type="string">
               <column name="USER_MOBILE" not-null="true"/>
            </property>

       <set name="Interests" table="USER_INTERESTS" lazy="false">
          <key column="USER_NICK" />
          <many-to-many column="INTEREST_ID" class="com.rcg.bn.InterestClass"/>
      </set>

        <set name="Communities" table="USER_COMMUNITIES" lazy="false">
          <key column="USER_NICK"  />
          <many-to-many column="COMMUNITY_ID" class="com.rcg.bn.CommunityClass"/>
      </set>
   </class>
</hibernate-mapping>




InterestClass

Code:
<hibernate-mapping auto-import="true">
        <class name="InterestClass" table="INTERESTS">
        <id name="Id" type="long" >
               <column name="INTEREST_ID" not-null="true"/>
                      <generator class="increment" />
                 </id>
            <property name="Title" type="string">
                   <column name="INTEREST_TITLE" length="255" not-null="true"/>
              </property>
          </class>
</hibernate-mapping>


CommunityClass
Code:
<hibernate-mapping auto-import="true">
    <class name="com.rcg.bn.CommunityClass" table="COMMUNITY">
        <id name="Id" type="string" >
               <column name="COMMUNITY_ID" not-null="true"/>
               <generator class="assigned" />
           </id>

           <property name="Name" type="string">
               <column name="COMMUNITY_NAME" length="255" not-null="true"/>
            </property>
           <property name="Creator" type="string">
               <column name="COMMUNITY_CREATOR" length="255" not-null="true"/>
            </property>
           <property name="Description" type="string">
               <column name="COMMUNITY_DESCRIPTION" length="255" not-null="false"/>
            </property>
           <property name="DateOfCreation" type="date">
               <column name="COMMUNITY_DATE" not-null="true"/>
            </property>
           <property name="Right" type="boolean">
               <column name="COMMUNITY_RIGHT" not-null="true"/>
            </property>

      <set name="Interests" table="COMMUNITY_INTERESTS" lazy="false">
          <key>
              <column name="COMMUNITY_ID" not-null="true" />
          </key>
          <many-to-many class="com.rcg.bn.InterestClass">

              <column name="INTEREST_ID" not-null="true"/>
          </many-to-many>
      </set>

    </class>
</hibernate-mapping>


Last edited by rezoal on Tue Aug 22, 2006 10:38 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 4:19 pm 
Regular
Regular

Joined: Fri Aug 18, 2006 2:40 pm
Posts: 51
Location: Metz, France
au lieu de
Code:
<many-to-many class="com.rcg.bn.InterestClass">
              <column name="INTEREST_ID" not-null="true"/>
</many-to-many>


essaie donc
Code:
<many-to-many column="INTEREST_ID" class="com.rcg.bn.InterestClass"/>

_________________
Denis
Don't forget to rate ... thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 9:43 am 
Newbie

Joined: Mon Aug 21, 2006 8:33 am
Posts: 2
Non ça ne résout rien .
J'ai fait un autre exemple (plus simple) avec 2 Set au cas où c'est hibernate-tools (mais ça m'aurait étonné) qui ne prend pas en compte 2 Set à la suite mais là ça marche bien .. .
Je suppose donc que c'est mon mapping soit de CommunityClass soit de UserClass qui est erronné... pourtant je n'ai pas d'erreur.

Sinon je pense que cela vient de ça :

J'essaie de créer avec mysql à la main la table USER_COMMUNITIES
Code:
create table USER_COMMUNITIES ( USER_NICK VARCHAR(255) not null, COMMUNITY_ID VARCHAR(255) not null, primary key( USER_NICK, COMMUNITY_ID) );


Mysql me répond

Quote:
ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes


Possible que ce soit cela qui fait planté la génération de la table.... ... Mon charset étant en UTF8 ... il ne reste plus qu'à mettre le charset du system en latin1.

Je reposte si c'est résolu.


EDIT : Résolu : changement de charset et ça marche!!!

Résumé problème : les clefs de ma table USER_COMMUNITIES estr top longue ( taille > 1000 octets) cela est dû au charset UTF8 (3 octets par caractère) donc on ne pouvait pas créer la table.

Résolution du problème
: Changer le charset de la base en latin1 ou autre.

Ce n'est nullement un problème de configuration de hibernate ou des fichiers de mappings, "juste" de mysql

Sinon y aurait-il une option pour voir les logs de mysql de ce genre lors du lancement de Tomcat par exemple ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.