Discussions

General J2EE: HIBERNATE HELP

  1. HIBERNATE HELP (2 messages)

    Hello all,

    Im kind of new to Hibernate and ive been having some problems.
    I am trying to save a Group(id, set of parents), Parent(id,name,age,set of children), Child(name, age).

    I was wondering if it was possible to create a Group.
    Then fill that Group with Parents, and fill each Parent with Children. Then just make one call to save, and save the Group to the database, which would then intern store the Parents and Children or the Parent.

    Currently I have an error.

    It inserts data into Group,Parent,Group_Parents, and Parent_Child.

    But it doesnt insert into Child.

    Any ideas?

    Thanks,
    Scott

    Threaded Messages (2)

  2. HIBERNATE HELP[ Go to top ]

    Here are my xml files

    GroupPeople
    ----------
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping>

            <class name="de.gloegl.road2hibernate.GroupPeople" table="GroupPeople" lazy="false">
                    <id name="id" column="id" type="long">
                            <generator class="increment"/>
                    </id>
                    <set name="parents" cascade="all" table="Group_Parents" lazy="false">
    <key column="group_id"/>
                            <many-to-many column="parent_id" class="de.gloegl.road2hibernate.Parent"/>
                    </set>

            </class>

    </hibernate-mapping>

    parent
    -----------
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping>

            <class name="de.gloegl.road2hibernate.Parent" table="Parent" lazy="false">
                    <id name="id" column="uid" type="long">
                            <generator class="increment"/>
                    </id>
                    <property name="age"/>
                    <property name="name"/>
                    <set name="child" table="parents_child" lazy="false">
                        <key column="parent_uid"/>
                        <many-to-many class="de.gloegl.road2hibernate.Child"/>
                    </set>
            </class>

    </hibernate-mapping>

    child
    --------

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

    <hibernate-mapping>

            <class name="de.gloegl.road2hibernate.Child" table="Child" lazy="false">
                   <id name="id" column="uid" type="long">
                            <generator class="increment"/>
                    </id>
    <property name="name"/>
                    <property name="age"/>
                    
            </class>

    </hibernate-mapping>
  3. try this[ Go to top ]

    in the Parent xml file i believe u need a ' cascade="all" ' where you define the set of Child objects.

    ie.
    <set name="child" table="parents_child" lazy="false">

    should look like

    <set name="child" table="parents_child" cascade="all" lazy="false">

    ben