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;
}
QuestionWhen 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!!!