-->
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: how to load children based on a condition? Help urgent!!!
PostPosted: Wed Feb 15, 2006 5:21 pm 
Newbie

Joined: Tue Jan 17, 2006 12:51 pm
Posts: 8
Hibernate version: 3.1

Hello,
We have the following tables in our database.

Table 1
Part_Id - int identity (10) - Primary key
Part_Code - Char (10)
Part_Name - Varchar (50)
Deleted - int(1) - value zero or one


Table 2
Part_Id - int(10) - Foreign key -->Table1.Part_Id
Replacing_Part_Id - int(10) - Foreign key-->Table1.Part_Id
Deleted - int(1) - value zero or one
Part_Id & Replacing_Part_Id is a composite primary key in table2.


Rows are not be deleted physically in the database. They are marked as deleted. Value 0 in Deleted column indicates row is not deleted. Py key value in Deleted column indicates row is deleted.

HBM Mappings

CLASS1

Code:
   
   * @hibernate.set inverse="true" cascade="save-update" lazy = "false"
   * @hibernate.collection-key column="PART_ID"
   * @hibernate.collection-one-to-many class="CLASS2" 

     public Set getPartsThatReplacesThisPart() {
      return this.partsThatReplacesThisPart;;
      }



   * @hibernate.set inverse="true" cascade="save-update" lazy = "false"
   * @hibernate.collection-key column="REPLACING_PART_ID"
   * @hibernate.collection-one-to-many class="CLASS2" 
   
    public Set getPartsReplacedByThisPart() () {
    return this.partsReplacedByThisPart;
  }



CLASS2


Code:
  /* Two mappings defined for same instance variable*/
 
   * @hibernate.many-to-one column="PART_ID"  class="CLASS1"  cascade="save-update"
   * @hibernate.many-to-one column="REPLACING_PART_ID"  class="CLASS1"  cascade="save-update"

      public Part getPart() {
      return this.part;
     }



Question

When I call the method class1.getPartsThatReplacesThisPart()
I only want the children that have the Deleted column value = 0. How do you specify this in hibernate?

Code:
    <class name="CLASS2"
        table="Table2"
        [b]where="deleted = 0">[/b]


Specifying where condition in the class element of hbm mapping doesn't work.

Please help!!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 6:03 pm 
Newbie

Joined: Wed Oct 12, 2005 7:06 pm
Posts: 10
The Where should not be specified for the class. It should be specified for the set.

* @hibernate.set inverse="true" cascade="save-update" lazy = "false" where="deleted=1"

_________________
Lachu

don't forget the credit system ;-)


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.