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.  [ 1 post ] 
Author Message
 Post subject: [besoin d'aide] Création de table avec Mapping
PostPosted: Tue May 30, 2006 9:40 am 
Newbie

Joined: Mon May 29, 2006 7:44 pm
Posts: 2
Allo, je voulais créer 3 table: T_installation, T_substation et T_typePosteHQ.

T_substation hérite de T_installation, donc jai fait un joined-subclass dans le mapping et ça marche bien.

T_substation est supposé avoir une colonne "ID" qui serait sa clé primaire et une colonne "typePoste" qui serait une clé étrangère qui vient de la table T_typePosteHQ.

1 substation ne peut qu'avoir 1 type de T_typePosteHQ.

donc, j'ai fais une relation one to one, en espérant que la clé étrangère va bien se faire. Mais malheureusement, il a fait que ma colonne ID est la clé étrangère de T_typePosteHQ, et il n'a même pas créé la colonne "typePoste"...

Pouvez vous m'aider SVP?
merci beaucoup

Hibernate version:
hibernate-3.1

Mapping de T_installation avec T_substation:

Code:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

   
  <class name="T_installation" table="A_TEST_INSTALLATION">
 
    <id name="id">
      <generator class="sequence"/>
    </id>
    <version name="version" />
    <property name="local" />
    <property name="name" />
    <property name="nameHQ" />
    <property name="descr" />
    <property name="remarque" />
    <property name="pathSSD" />
    <property name="pathSCD" />
    <property name="region" column="nomRegion"/>
   
    <joined-subclass name="T_substation" table="A_TEST_SUBSTATION">
       <key column="ID"/>

       <property name="local"/>
       <property name="multibatiment" />    
       <property name="reutilisation" column="REUTIL" />

       <one-to-one
            cascade="all"
      constrained="true"
            name="typePoste"
            class="T_typePosteHQ"

         />
          
       
    </joined-subclass>
   
  </class>
 
</hibernate-mapping>




Mapping de T_typePosteHQ:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
 

  <class name="T_typePosteHQ" table="A_TEST_TYPEPOSTEHQ">   

    <id name="id">
      <generator class="sequence"/>
    </id>
   
    <property name="nom"/>
    <property name="description" column="DESCR" />

  </class>



Code between sessionFactory.openSession() and session.close():
Code:

        SessionFactory sessionFactory =
            (SessionFactory) context.getBean( "sessionFactory" );
        Session session = sessionFactory.openSession();
       
        Transaction transaction = null;
       
        try {
            transaction = session.beginTransaction();
           
            T_typePosteHQ poste = new T_typePosteHQ("test1", "test1");
           
            session.persist(poste);
            transaction.commit();

            T_substation substation = new T_substation(false, poste, 55555, 
                 "test", "test","test", "test",
                 "test", "test", 'P', "Quebec");
           
           
            transaction = session.beginTransaction();
            session.persist(substation);
            transaction.commit();

        } catch ( RuntimeException e ) {
            if ( transaction != null ) transaction.rollback();
            throw e; 
        } finally {
            session.close();
        }


Stack trace d'exception:

pas d'exception

Nom et version de ma base de donnée:
Oracle 10.1.0

SQL généré par hibernate (show_sql=true):
Quote:
Hibernate: select hibernate_sequence.nextval from dual

Hibernate: insert into A_TEST_TYPEPOSTEHQ (nom, DESCR, id) values (?, ?, ?)

Hibernate: select hibernate_sequence.nextval from dual

Hibernate: insert into A_TEST_INSTALLATION (version, local, name, nameHQ, descr, remarque, pathSSD, pathSCD, nomRegion, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Hibernate: insert into A_TEST_SUBSTATION (local, multibatiment, REUTIL, ID) values (?, ?, ?, ?)

Hibernate: update A_TEST_INSTALLATION set version=?, local=?, name=?, nameHQ=?, descr=?, remarque=?, pathSSD=?, pathSCD=?, nomRegion=? where id=? and version=?


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

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.