openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Judes Tumuhairwe <judethecuted...@gmail.com>
Subject Re: Single table discriminator strategies
Date Thu, 04 Feb 2010 02:18:13 GMT
Olivier,
I don't think that's possible. According to the spec  (section 2.1.10.1)
they all have to be in one table.

If you anticipate change, have you considered using a view instead (it seems
to me that would easier)
 [ CREATE VIEW myView AS
   SELECT a.*, discriminator.value FROM a, discriminator WHERE a.id =
discriminator.id ]

and then map the entity to the view (then if things change in the future,
you can just change the SQL in the myView)?

regards,
Judes Tumuhairwe

On Wed, Feb 3, 2010 at 6:09 PM, Olivier Houyoux
<olivier.houyoux@gmail.com>wrote:

>
> Hi,
>
>
> In a single table inheritance strategy, would it be possible to use any
> additional JPA mapping to define a discriminator strategy that will get
> discriminator values in a different table ?
>
>
> For example, from the given database schema and classes :
>
>
>
> create table A (
>   ID integer primary key not null,
>   ...
>   DISCR varchar,
> ) ;
>
> @Entity
> @Table(name = "A")
> @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
> @DiscriminatorColumn(name = "DISCR", discriminatorType =
> DiscriminatorType.STRING)
> public abstract class A {
>    ...
> }
>
> @Entity
> @DiscriminatorValue("foo")
> public class B extends A {
>    ...
> }
>
>
> if the database schema changes a little,
>
>
> create table A (
>   ID integer primary key not null,
>   ...
>   DISCR integer,
> ) ;
>
> create table DISCRIMINATOR (
>   ID integer primary key not null,
>   ...
>   VALUE varchar
> ) ;
>
>
> would it be possible to change the DiscriminatorColumn annotation in the A
> class to search for the discriminator value in DISCRIMINATOR.VALUE instead
> of A.DISCR, assuming that A.DISCR will no longer contain string data but
> DISCRIMATOR primary key ?
>
> Thank you for your idea.
> --
> View this message in context:
> http://n2.nabble.com/Single-table-discriminator-strategies-tp4510595p4510595.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message