I have the following inheritance hierarchy.
@Entity
@Table(FRUIT)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColum(name="FRUIT_TYPE",discriminatorType=STRING)
public class Fruit {
..
@Id
private FruitId id;
...
}
@DiscriminatorValue("APPLE")
public class Apple extends Fruit {
...
@ManyToOne
private FruitBowl bowl; //this association is only present in the subclass
...
}
class FruitBowl .. {
...
@OneToMany(fetch = FetchType.LAZY, mappedBy = "bowl")
@IndexColumn(name="POSITION",base = 1)
List<Apple> apples;
...
When I do a session.load(Apple.class,...)
, it adds FRUIT_TYPE = 'APPLE'
to the select query. But if I do a select on FruitBowl(which has a 1:m relationship with Apple), the select query on the Apple does not contain FRUIT_TYPE = 'APPLE'
. Why does this happen? How do I rectify the problem?
Query --Query for FruitBowl
select fruitbowl0_.BOWL_ID as BOWL1_1_0_ from FRUITBOWL fruitbowl0_ where fruitbowl0_.BOWL_ID=?
--Query for Fruit to retrieve Apples (records with fruit_type ='A') --but it does not include that condition
select apples0_.ENTITY_ID as ENTITY3_1_, apples0_.POS as POS1_, apples0_.POS as POS0_0_, apples0_.ENTITY_ID as ENTITY3_0_0_, apples0_.COLOR as COLOR0_0_ from FRUIT apples0_ where apples0_.ENTITY_ID=?