Hibernate version:3.3.1 GA
Hello,
I have an odd theoretical problem.
I have this situation:
bean Parent and Child.
class Parent {
Child c;
setChild(c) {
this.c = c;
}
Child getChild() {
return c;
}
}
My mappings:
<class name="org.myproject.Parent" entity-name="Parent" table="PARENT_TABLE">
<id name="parentId" column="PARTENTID">
<generator class="native" />
</id>
<many-to-one name="child" entity-name="Child" column="CHILDID" not-null="true" />
{....other attributes}
</class>
<class name="org.myproject.Child" entity-name="Child" table="CHILD_TABLE">
<id name="childId" column="CHILDID">
<generator class="native" />
</id>
{....other attributes}
</class>
There are functionalities in my application that boiles down to having selects where I need only a condition on PARENT_TABLE.CHILDID = ?.
For example:
When I need to put the condition on Parent.childId = -999; where -999 might be a sort of void id, like a flag for a parent
with a fake child.
I this case the select will be something like this:
select * from PARENT_TABLE P inner join CHILD_TABLE c on p.CHILDID = c.CHILDID where c.CHILDID = -999 but actually I need something like this:
select * from PARENT_TABLE p where p.CHILDID = -999.
How can I achive this, as my entity Parent doesn't have a primitive attribute mapped exactly on CHILDID column but only the relation many-to-one
with the Child table through the Child object.
I solved this problem by adding childId to Parent object, and adding the coresponding mapping, but I think this is not the real solution.
class Parent {
Child c;
int childId;
setChild(c) {
this.c = c;
}
Child getChild() {
return c;
}
setChildId(childId) {
this.childId = childId;
}
int getChildId() {
return childId;
}
}
My mappings:
<class name="org.myproject.Parent" entity-name="Parent" table="PARENT_TABLE">
<id name="parentId" column="PARTENTID">
<generator class="native" />
</id>
<property name="childId" column="CHILDID" />
<many-to-one name="child" entity-name="Child" column="CHILDID" not-null="true" />
{....other attributes}
</class>
Thanks
|