-->
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: polymorphism mapping with many-to-many
PostPosted: Tue Nov 27, 2007 5:56 am 
Newbie

Joined: Mon Nov 26, 2007 6:15 am
Posts: 2
i everybody this is my case, i have 4 classes Typedico, Groupe, Composant, Service, the 3 last classes inherit from Typedico here the SQL script:
Code:
CREATE TABLE typedico
(
  typedicoid integer NOT NULL DEFAULT nextval('serie'::regclass),
  nom text,
  commentaire text,
  typedico_type text,
  CONSTRAINT pk_typedico PRIMARY KEY (typedicoid)
)
CREATE TABLE groupe
(
  groupeid integer NOT NULL DEFAULT nextval('serie'::regclass),
  typedicoid integer,
  typedico boolean,
  CONSTRAINT pk_groupe PRIMARY KEY (groupeid),
  CONSTRAINT fk_groupe_groupe_ty_typedico FOREIGN KEY (typedicoid)
      REFERENCES typedico (typedicoid) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE RESTRICT
)
CREATE TABLE groupes
(
  groupeid integer NOT NULL,
  utilisateurid integer NOT NULL,
  CONSTRAINT pk_groupes PRIMARY KEY (groupeid, utilisateurid),
  CONSTRAINT fk_groupes_groupes_groupe FOREIGN KEY (groupeid)
      REFERENCES groupe (groupeid) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE RESTRICT,
  CONSTRAINT fk_groupes_groupes_utilisat FOREIGN KEY (utilisateurid)
      REFERENCES utilisateur (utilisateurid) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE RESTRICT

CREATE TABLE composant
(
  composantid integer NOT NULL DEFAULT nextval('serie'::regclass),
  typedicoid integer,
  typedico boolean,
  statut text,
    CONSTRAINT pk_composant PRIMARY KEY (composantid),
  CONSTRAINT fk_composan_composant_typedico [b]FOREIGN KEY (typedicoid)[/b]      REFERENCES typedico (typedicoid) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE RESTRICT
)
CREATE TABLE service
(
  serviceid integer NOT NULL DEFAULT nextval('serie'::regclass),
  typedicoid integer,
  typedico boolean,
  CONSTRAINT pk_service PRIMARY KEY (serviceid),
  CONSTRAINT fk_service_service_t_typedico FOREIGN KEY (typedicoid)
      REFERENCES typedico (typedicoid) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE RESTRICT
)


An object Composant can have many Service and Service many Composant the relationship, between Composant and Service is many-to-many. This is my XML document to map this class.
Code:
<hibernate-mapping package="com.myapp.exploreoffre.javabeans" default-lazy="true">
    <class name="Typedico" table="typedico" dynamic-update="true" dynamic-insert="true">
        <id name="typedicoid" column="typedicoid" unsaved-value="0">
            <generator class="sequence">
                <param name="sequence">serie</param>
            </generator>
        </id>
        <property name="typedicoid" column="typedicoid" insert="false" update="false"/>
        <property name="nom" column="nom"/>
        <property name="commentaire" column="commentaire"/>
<joined-subclass name="Service" table="service">
            <key column="typedicoid"/>
            <property name="serviceid" column="serviceid" insert="false" update="false"/>
            <property name="typedico" column="typedico" type="boolean"/>
            <property name="description" column="description"/>
            <property name="compris" column="compris" type="boolean"/>   
        </joined-subclass>
        <joined-subclass name="Groupe" table="groupe">
            <key column="typedicoid"/>
            <property name="groupeid" column="groupeid" insert="false" update="false"/>
            <property name="typedico" column="typedico" type="boolean"/>
        </joined-subclass>       
        <joined-subclass name="Composant" table="composant">
            <key column="typedicoid"/>
            <property name="composantid" column="composantid" insert="false" update="false"/>
            <property name="typedico" column="typedico" type="boolean"/>
            <property name="statut" column="statut"/>
            <property name="type" column="type"/>
            <property name="duree" column="duree" type="java.util.GregorianCalendar"/>
            <property name="debut" column="debut" type="java.util.GregorianCalendar"/>
            <property name="description" column="description"/>
            <property name="descriptionsimple" column="descriptionsimple"/>
            <property name="prix" column="prix"/>     
            <set name="paragraphes" table="paragraphes">
                <key column="composantid"/>
                <many-to-many class="Paragraphe"/>
            </set>
            <set name="services" table="services">
                <key column="composantid"/>
                <many-to-many class="Service"/>
            </set>
            <set name="themes" table="themes">
                <key column="composantid"/>
                <many-to-many class="Theme"/>
            </set>
            <set name="options" table="options">
                <key column="composantid"/>
                <many-to-many class="Option"/>
            </set>
            <set name="conditions" table="conditions">
                <key column="composantid"/>
                <many-to-many class="Condition"/>
            </set>
            <set name="lieux" table="lieux">
                <key column="composantid"/>
                <many-to-many class="Lieu"/>
            </set>
        </joined-subclass>       
    </class>
</hibernate-mapping>

when i try to store a new Utilisateur Object who have many Groupe nothing happens, here is the code and hibernate output.
Code:
BeanUtils.copyProperties(utilisateur, fillform.getUtilisateur());
                BeanUtils.copyProperties(utilisateur.getAuthentification(), fillform.getUtilisateur().getAuthentification());
                new HibernateDAO().insert(utilisateur);
                for (int dI = 0; dI < fillform.getIdentifiants().length; dI++) {
                    groupe = (Groupe) new HibernateDAO().find(new Groupe(), new Integer(fillform.getIdentifiants(dI)));
                    utilisateur.addGroupes(groupe);
                }       
                form.reset(mapping, request);
                return mapping.findForward("utilisateur");

Hibernate Output
Code:
Hibernate: select nextval ('serie')
Hibernate: select nextval ('serie')
Hibernate: /* insert com.myapp.exploreoffre.javabeans.Authentification */ insert into authentification (identifiant, password, authentificationid) values (?, ?, ?)
Hibernate: /* insert com.myapp.exploreoffre.javabeans.Utilisateur */ insert into personne (nom, prenom, email, telephone, fax, gsm, personneid) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: /* insert com.myapp.exploreoffre.javabeans.Utilisateur */ insert into utilisateur (initiale, authentificationid, personneid) values (?, ?, ?)
Hibernate: /* load com.myapp.exploreoffre.javabeans.Groupe */ select groupe0_.typedicoid as typedicoid6_0_, groupe0_1_.nom as nom6_0_, groupe0_1_.commentaire as commenta3_6_0_, groupe0_.groupeid as groupeid15_0_, groupe0_.typedico as typedico15_0_ from groupe groupe0_ inner join typedico groupe0_1_ on groupe0_.typedicoid=groupe0_1_.typedicoid where groupe0_.typedicoid=?
Hibernate: /* load com.myapp.exploreoffre.javabeans.Groupe */ select groupe0_.typedicoid as typedicoid6_0_, groupe0_1_.nom as nom6_0_, groupe0_1_.commentaire as commenta3_6_0_, groupe0_.groupeid as groupeid15_0_, groupe0_.typedico as typedico15_0_ from groupe groupe0_ inner join typedico groupe0_1_ on groupe0_.typedicoid=groupe0_1_.typedicoid where groupe0_.typedicoid=?

As I can see Hibernate has add new class Utilisateur with new Authentification , he loads the two Groupe, which was selected in the jsp but didn't update the table Groupeswith ID's of Utilisateur and Groupecan somebody help to map correcly this case. thanks in advance.


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.