Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Hibernate mapping problem of parent

Thread view: 
sss.zhou@gmail.com - 09 Sep 2007 12:04 GMT
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;
  }
David  Portabella - 09 Sep 2007 16:24 GMT
On Sep 9, 1:04 pm, "sss.z...@gmail.com" <sss.z...@gmail.com> wrote:
> The mapping attributeparent="xxx" doesn't work
>
[quoted text clipped - 66 lines]
>       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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.