Create a superclass and 2 subclasses on the same table.
There will be an extra column (which determines the type (the discriminator
column), and may be optionally configured through annotations.
@Entity
@DiscriminatorColumn(name="type")
public class Base {
//All persistent fields go here
}
@Entity
@DiscriminatorValue("a")
public class ClassA extends Base {
...
}
@Entity
@DiscriminatorValue("b")
public class ClassB extends Base {
...
}
Luis Fernando Planella Gonzalez
Em Quarta-feira 24 Junho 2009, às 03:54:22, ashish paliwal escreveu:
> Hi,
>
> I have a scenario. I have an existing schema where ClassA maps to TableA.
> Now, I want to create a new class, ClassB which also maps to this very same
> table. Functionaliyt that I require is that when data is searched for ClassA
> instances, only records which were inserted by making Objects of ClassA
> should be returned and no records that were created by making classB objects
> should be returned.
> For example- If I insert 3 records by making 3 Objects of classA and
> persisting them and similarly I insert 2 records by making Object of classB
> then persisting them then when I fire query "select a from classA a", only 3
> records should be returned.
> I wanted to know that is it possible in OpenJPA and is there any defination
> in JPA using which I can map 2 classes to same table.
>
> thanks and regards
>