-->
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: Hibernate one to many , collection, bag
PostPosted: Wed Oct 03, 2007 3:47 pm 
Newbie

Joined: Wed Oct 03, 2007 3:32 pm
Posts: 1
Hi, I have

Code:
public class A{
private int idA;
private String nameA;
private List <B> bs
}

public class B{
private int idB;
private String nameB;
}


Now in my database i have;
**********
Table A
idA (PK)
nameA
**********
**********
TAble B
idB (PK)
idA (FK)
nameB
**********


Now i already have in table A (5,"row1A") and in B i have (1,5,"row1B")
i want to add in B one more row so i'll have (1,5,"row1B") (2,5,"row1B")

so i can't figure out what to do in my method
Code:
  try {
            session = hibernateFactory.openSession();           
            tx = session.beginTransaction();
            ?
            ?
            ?
            tx.commit();   
            session.flush ();
        }
        catch (RuntimeException e){
            tx.rollback ();
            e.printStackTrace ();           
        }
        finally {
            session.close ();
        }




My hbm.xml are:
Code:
<hibernate-mapping package="seguridad.entidad">
    <class  name="Sistema" table="sistema" lazy="false" >   
        <id name="cod_sistema" type="java.lang.Integer" >
            <column  name="cod_sistema"  not-null="true"/>
            <generator class="increment"/>
        </id>       
        <property 
            name="nom_sistema"
            type="java.lang.String"
            update="true"
            insert="true"
            column="nom_sistema"
        />       
        <property
            name="ind_bloqueo"
            type="java.lang.Boolean"
            update="true"
            insert="true"
            column="ind_bloqueo"
        />
        <property
            name="url_index"
            type="java.lang.String"
            update="true"
            insert="true"
            column="url_index"
        />       
        <bag name="modulos" cascade="all">           
            <key column="cod_sistema"/>                           
            <one-to-many class="Modulo"/>
        </bag>
    </class>   
</hibernate-mapping>

<hibernate-mapping package="seguridad.entidad">
    <class  name="Modulo" table="modulo" lazy="false" >
        <id  name="cod_modulo"  type="java.lang.Integer" >
            <column  name="cod_modulo"  not-null="true"/>
            <generator class="increment"/>
        </id>       
        <property 
            name="nom_modulo"
            type="java.lang.String"
            update="true"
            insert="true"
            column="nom_modulo"
        />       
        <property
            name="ind_bloqueo"
            type="java.lang.Boolean"
            update="true"
            insert="true"
            column="ind_bloqueo"
        />
        <bag name="paginas" cascade="all">           
            <key column="cod_modulo"/>                           
            <one-to-many class="Pagina"/>
        </bag>
    </class>   
</hibernate-mapping>


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.