-->
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.  [ 2 posts ] 
Author Message
 Post subject: problem mapping one-to-many within the same class
PostPosted: Tue Sep 02, 2003 7:11 am 
Newbie

Joined: Tue Sep 02, 2003 6:45 am
Posts: 1
Location: Cape Town, SA
I have this class which has a reference to itself as parent:
Code:
public class Vendor extends VObject {

   private String id;
   private String name;
   private Timestamp timestamp;
   private String companyName;
   private String contactName;
   private Vendor vendor;
   private Set vendors = new HashSet();
   private String contactCellNo;

   public void setId(String id) {
      this.id = id;
   }

   public String getId() {
      return id;
   }

   public String getName() {
      return this.name;
   }

   public void setName(String name) {
      this.name = name;
   }
   
   public Timestamp getTimestamp() {
      if (timestamp==null) timestamp = new Timestamp(System.currentTimeMillis());
      return timestamp;
   }
   
   public void setTimestamp(Timestamp value) {
      timestamp = value;
   }

   public String getCompanyName() {
      return this.companyName;
   }

   public void setCompanyName(String companyName) {
      this.companyName = companyName;
   }

   public String getContactName() {
      return this.contactName;
   }

   public void setContactName(String contactName) {
      this.contactName = contactName;
   }

   public Vendor getVendor() {
      return this.vendor;
   }

   public void setVendor(Vendor vendor) {
      this.vendor = vendor;
   }


   public void setVendors(Set vendors) {
      this.vendors = vendors;
   }

   public String getContactCellNo() {
      return this.contactCellNo;
   }

   public void setContactCellNo(String contactCellNo) {
      this.contactCellNo = contactCellNo;
   }

   public Set getVendors() {
      
      return this.vendors;
   }

}


My problem is simply this:
(a) All the examples assumes that "children" should for some odd reason always be e different class.
(b) According to the reference manual:
* It does not matter if a one-to-many relationship point to the same column/table
* Only one end of the relationship should be marked as readonly.
(c) If tried it does not work.
(d) The DTD does not allow for a <set> element to hava "readonly" attrib. If i drop it expects a "role" attribute (which is rejected once again by the DTD).
(e) If i leave the role attrib I get a massive milelong nullpointer exception; I traced the exception, and I ended up in Root class which expects a role attribute.

Where did i go wrong? I scanned the FAQ, and tutorials. I simply dont have the time to spent on browsing the www anymore.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 7:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ummmm. I think you should spend some more time.


You would discover


(a) there are 2 different Hibernate DTDs, one for Hibernate 1.2.x, and another for Hibernate2

(b) there is not readonly or role attribtes in Hibernate2, they are renamed inverse and role

(c) there are PLENTY of examples of self-referential relationships, both on the Wiki, and in serc/net/sf/hibernate/test


(b) POLITELNESS will get you much further in life


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.