tags:

views:

21

answers:

1

Hi,

Assume i have:

@Inheritance(strategy = InheritanceType.JOINED)
public class Child extends Parent{
}

How can i do a selection of only the instances saved as a Parent, not as a Child.

Thank you

A: 

Take a look at the bottom of section 14.9 of the Hibernate documentation:

The special property class accesses the discriminator value of an instance in the case of polymorphic persistence. A Java class name embedded in the where clause will be translated to its discriminator value.

from Cat cat where cat.class = DomesticCat

So I believe in your case you could use the HQL constraint ... where class=Parent to filter out the instances of Child.

Andrzej Doyle
Great! It worked:) Didn't see it in the docs. In Criteria i used c.add(Restrictions.eq("class", Parent.class));
Michael Bavin