Hibernate mapping problem of parent

Discussion in 'Java' started by sss.zhou@gmail.com, Sep 9, 2007.

  1. Guest

    The mapping attribute parent="xxx" doesn't work

    Hibernate Version: version 3.2.5

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

    <hibernate-mapping package="parenttest">
    <class name="Parent" table="PARENT">
    <id name="id" column="PARENT_ID" type="long">
    <generator class="native"/>
    </id>
    <property name="name" column="NAME" type="string"/>

    <set name="Childs" table="CHILDS">
    <key column="CHILD_ID"/>
    <composite-element class="Child">
    <parent name="Parent"/>
    <property name="username" column="ADDED_BY_USER"
    type="string"/>
    </composite-element>
    </set>
    </class>
    </hibernate-mapping>


    But I get the Child.java class source file by hbm2java.

    package parenttest;
    // Generated 2007-9-9 17:42:40 by Hibernate Tools 3.2.0.b9

    /**
    * Child generated by hbm2java
    */
    public class Child implements java.io.Serializable {

    private String username;

    public Child() {
    }

    public Child(String username) {
    this.username = username;
    }

    public String getUsername() {
    return this.username;
    }

    public void setUsername(String username) {
    this.username = username;
    }
    }


    The code of Parent.java is OK.

    So what's wrong with the mapping files? I want the Child to have the
    getter and setter of parent. I see the parent tag do this work in
    hibernate document.


    private Parent parent;
    public Parent getParent() {
    return parent;
    }

    public void setParent(Parent parent) {
    this.parent = parent;
    }
    , Sep 9, 2007
    #1
    1. Advertising

  2. On Sep 9, 1:04 pm, "" <> wrote:
    > The mapping attributeparent="xxx" doesn't work
    >
    > Hibernate Version: version 3.2.5
    >
    > <?xml version="1.0"?>
    > <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
    > DTD//EN"
    > "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    >
    > <hibernate-mapping package="parenttest">
    > <class name="Parent" table="PARENT">
    > <id name="id" column="PARENT_ID" type="long">
    > <generator class="native"/>
    > </id>
    > <property name="name" column="NAME" type="string"/>
    >
    > <set name="Childs" table="CHILDS">
    > <key column="CHILD_ID"/>
    > <composite-element class="Child">
    > <parent name="Parent"/>
    > <property name="username" column="ADDED_BY_USER"
    > type="string"/>
    > </composite-element>
    > </set>
    > </class>
    > </hibernate-mapping>
    >
    > But I get the Child.java class source file by hbm2java.
    >
    > packageparenttest;
    > // Generated 2007-9-9 17:42:40 by Hibernate Tools 3.2.0.b9
    >
    > /**
    > * Child generated by hbm2java
    > */
    > public class Child implements java.io.Serializable {
    >
    > private String username;
    >
    > public Child() {
    > }
    >
    > public Child(String username) {
    > this.username = username;
    > }
    >
    > public String getUsername() {
    > return this.username;
    > }
    >
    > public void setUsername(String username) {
    > this.username = username;
    > }
    >
    > }
    >
    > The code ofParent.java is OK.
    >
    > So what's wrong with the mapping files? I want the Child to have the
    > getter and setter ofparent. I see theparenttag do this work in
    > hibernate document.
    >
    > privateParentparent;
    > publicParentgetParent() {
    > returnparent;
    > }
    >
    > public void setParent(Parentparent) {
    > this.parent=parent;
    > }



    I don't understand your line:
    <parent name="Parent"/>

    Is "parent" a valid element in the hibernate config?
    To get the effect you asked, you could substitute the previous line
    by:

    <many-to-one name="parent" class="parenttest.Parent"
    column="PARENT_ID"/>

    HTH,
    DAvid
    David Portabella, Sep 9, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ilias Lazaridis
    Replies:
    0
    Views:
    1,713
    Ilias Lazaridis
    Dec 27, 2004
  2. Replies:
    7
    Views:
    4,607
    lars.egarots
    Jul 22, 2008
  3. garhone

    Hibernate mapping problem

    garhone, Aug 24, 2006, in forum: Java
    Replies:
    0
    Views:
    425
    garhone
    Aug 24, 2006
  4. ducnbyu
    Replies:
    2
    Views:
    6,131
    ducnbyu
    Sep 8, 2006
  5. Replies:
    0
    Views:
    370
Loading...

Share This Page