You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Leonardo NOLETO <lf...@genigraph.fr> on 2009/05/07 16:30:07 UTC

TABLE_PER_CLASS does not work as described in JSR-200 (JPA-1.0)

Hi,

I have a big problem with TABLE_PER_CLASS mapping...I want map each concrete
classes in my class hierarchy to a separate table (in accordance with
JSR-200 page 39 - Table per Concrete Class Strategy)

When I use OpenJPA as provider, I have the following behavior :

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
abstract class RootClass { // persistent properties}

@Entity
@Table(name="BAR_TABLE")
class Bar extends RootClass {...}

@Entity
abstract AbstractFoo extends RootClass { // extra attributes }

@Entity
@Table(name="FOO1_TABLE")
class Foo1 extends AbstractFoo {...}

@Entity
@Table(name="FOO2_TABLE")
class Foo2 extends AbstractFoo {...}

The image below helps to visualize my problem:

http://n2.nabble.com/file/n2828426/tpc_issue_openjpa2.png 

If I use Hibernate as provider this works fine.

Does anyone know why?

I use openjpa-1.2.0.

-- 
View this message in context: http://n2.nabble.com/TABLE_PER_CLASS-does-not-work-as-described-in-JSR-200-%28JPA-1.0%29-tp2828426p2828426.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: TABLE_PER_CLASS does not work as described in JSR-200 (JPA-1.0)

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi,

OpenJPA allows mixing inheritance types in the hierarchy.

Can you try annotating each class with the @Inheritance annotation?

The inheritance strategy for the abstract class should be subclass to  
avoid having a table for the abstract class.

Craig

On May 7, 2009, at 7:30 AM, Leonardo NOLETO wrote:

>
> Hi,
>
> I have a big problem with TABLE_PER_CLASS mapping...I want map each  
> concrete
> classes in my class hierarchy to a separate table (in accordance with
> JSR-200 page 39 - Table per Concrete Class Strategy)
>
> When I use OpenJPA as provider, I have the following behavior :
>
> @Entity
> @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
> abstract class RootClass { // persistent properties}
>
> @Entity
> @Table(name="BAR_TABLE")
> class Bar extends RootClass {...}
>
> @Entity
> abstract AbstractFoo extends RootClass { // extra attributes }
>
> @Entity
> @Table(name="FOO1_TABLE")
> class Foo1 extends AbstractFoo {...}
>
> @Entity
> @Table(name="FOO2_TABLE")
> class Foo2 extends AbstractFoo {...}
>
> The image below helps to visualize my problem:
>
> http://n2.nabble.com/file/n2828426/tpc_issue_openjpa2.png
>
> If I use Hibernate as provider this works fine.
>
> Does anyone know why?
>
> I use openjpa-1.2.0.
>
> -- 
> View this message in context: http://n2.nabble.com/TABLE_PER_CLASS-does-not-work-as-described-in-JSR-200-%28JPA-1.0%29-tp2828426p2828426.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: TABLE_PER_CLASS does not work as described in JSR-220 (JPA-1.0)

Posted by Michael Dick <mi...@gmail.com>.
Hi Jody,

Using @MappedSuperclass may be "more correct" for this scenario, but I don't
think it's a requirement in general.

I'm not sure why introducing an abstract class in the hierarchy would
require a reset of the inheritance strategy. Abstract classes cannot have an
instance but you can query across their subclasses.

-mike

On Wed, May 20, 2009 at 7:46 PM, Jody Grassel <fy...@gmail.com> wrote:

> Looking at your data model, you're intending the class AbstractFoo to
> define
> new persistent types without AbstractFoo having a table mapping.  Instead
> of
> annotating the abstract class with the @Entity annotation, I think you
> should use the @MappedSuperclass annotation.
> What I think should be determined is if an abstract class annotated with
> @Entity should "reset" the inheritance hierarchy (as the only reason for
> the existence of such a definition would be to provide an inheritance base,
> abstract types can't have their own instance, so they must be extended by
> another class.) or throw an error during enhancement/runtime.
>
> On Wed, May 20, 2009 at 6:19 PM, Serge Bogatyrev
> <se...@gmail.com>wrote:
>
> > I've created an issue: OPENJPA-1096 <
> > https://issues.apache.org/jira/browse/OPENJPA-1096>
> >
> >
> > Craig L Russell wrote:
> >
> >> Hi Serge,
> >>
> >> Could you please open a JIRA so we can track this issue?
> >>
> >> Thanks,
> >>
> >> Craig
> >>
> >> On May 11, 2009, at 11:03 AM, Serge Bogatyrev wrote:
> >>
> >>  This mixed strategy can be very usefull. But obviously there is
> >>> uncompatibility with standards. I think that additional annotation can
> be
> >>> used to change standard behaviour. So, at this example strict
> >>> TABLE_PER_CLASS strategy should work without any additional
> annotations. And
> >>> to get the mixed strategy we shoud add @Inheritance annotation to some
> class
> >>> in hierarchy (e.g. AbsractFoo).
> >>>
> >>> Pinaki Poddar:
> >>>
> >>>> You are right. OpenJPA should use the inheritance strategy used at the
> >>>> root
> >>>> of the hierarchy throughout the derived tree. The extra strategy
> >>>> specification perhaps is resulting from the facility to support mixed
> >>>> strategy. Needs further investigation...
> >>>>
> >>>>
> >>>> hallmit wrote:
> >>>>
> >>>>  Thanks guys, I put
> >>>>> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
> >>>>> to AbstractFoo and now it works fine...I have also put
> >>>>> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) to the first
> >>>>> concrete class of my class hierarchy otherwise the SINGLE_TABLE
> >>>>> strategy
> >>>>> is used for the branch.    I thought it was sufficient to annotate
> the
> >>>>> root class with
> >>>>> TABLE_PER_CLASS and so all classes in the hierarchy would have the
> same
> >>>>> strategy...apparently not for OpenJPA...
> >>>>>
> >>>>> JSR 220 (JPA-1.0) spec talk :
> >>>>>
> >>>>> "The Inheritance annotation defines the inheritance strategy to be
> used
> >>>>> for an entity class hierarchy.
> >>>>> It is specified on the entity class that is the root of the entity
> >>>>> class
> >>>>> hierarchy."
> >>>>> ...
> >>>>>    In any case thank you very much for your help!
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>>> -----
> >>>> Pinaki Poddar                      http://ppoddar.blogspot.com/
> >>>>
> >>>> http://www.linkedin.com/in/pinakipoddar
> >>>> OpenJPA PMC Member/Committer
> >>>> JPA Expert Group Member
> >>>>
> >>>>
> >>>
> >> Craig L Russell
> >> Architect, Sun Java Enterprise System http://db.apache.org/jdo
> >> 408 276-5638 mailto:Craig.Russell@sun.com
> >> P.S. A good JDO? O, Gasp!
> >>
> >>
> >
>

Re: TABLE_PER_CLASS does not work as described in JSR-220 (JPA-1.0)

Posted by Jody Grassel <fy...@gmail.com>.
Looking at your data model, you're intending the class AbstractFoo to define
new persistent types without AbstractFoo having a table mapping.  Instead of
annotating the abstract class with the @Entity annotation, I think you
should use the @MappedSuperclass annotation.
What I think should be determined is if an abstract class annotated with
@Entity should "reset" the inheritance hierarchy (as the only reason for
the existence of such a definition would be to provide an inheritance base,
abstract types can't have their own instance, so they must be extended by
another class.) or throw an error during enhancement/runtime.

On Wed, May 20, 2009 at 6:19 PM, Serge Bogatyrev
<se...@gmail.com>wrote:

> I've created an issue: OPENJPA-1096 <
> https://issues.apache.org/jira/browse/OPENJPA-1096>
>
>
> Craig L Russell wrote:
>
>> Hi Serge,
>>
>> Could you please open a JIRA so we can track this issue?
>>
>> Thanks,
>>
>> Craig
>>
>> On May 11, 2009, at 11:03 AM, Serge Bogatyrev wrote:
>>
>>  This mixed strategy can be very usefull. But obviously there is
>>> uncompatibility with standards. I think that additional annotation can be
>>> used to change standard behaviour. So, at this example strict
>>> TABLE_PER_CLASS strategy should work without any additional annotations. And
>>> to get the mixed strategy we shoud add @Inheritance annotation to some class
>>> in hierarchy (e.g. AbsractFoo).
>>>
>>> Pinaki Poddar:
>>>
>>>> You are right. OpenJPA should use the inheritance strategy used at the
>>>> root
>>>> of the hierarchy throughout the derived tree. The extra strategy
>>>> specification perhaps is resulting from the facility to support mixed
>>>> strategy. Needs further investigation...
>>>>
>>>>
>>>> hallmit wrote:
>>>>
>>>>  Thanks guys, I put
>>>>> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
>>>>> to AbstractFoo and now it works fine...I have also put
>>>>> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) to the first
>>>>> concrete class of my class hierarchy otherwise the SINGLE_TABLE
>>>>> strategy
>>>>> is used for the branch.    I thought it was sufficient to annotate the
>>>>> root class with
>>>>> TABLE_PER_CLASS and so all classes in the hierarchy would have the same
>>>>> strategy...apparently not for OpenJPA...
>>>>>
>>>>> JSR 220 (JPA-1.0) spec talk :
>>>>>
>>>>> "The Inheritance annotation defines the inheritance strategy to be used
>>>>> for an entity class hierarchy.
>>>>> It is specified on the entity class that is the root of the entity
>>>>> class
>>>>> hierarchy."
>>>>> ...
>>>>>    In any case thank you very much for your help!
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>> -----
>>>> Pinaki Poddar                      http://ppoddar.blogspot.com/
>>>>
>>>> http://www.linkedin.com/in/pinakipoddar
>>>> OpenJPA PMC Member/Committer
>>>> JPA Expert Group Member
>>>>
>>>>
>>>
>> Craig L Russell
>> Architect, Sun Java Enterprise System http://db.apache.org/jdo
>> 408 276-5638 mailto:Craig.Russell@sun.com
>> P.S. A good JDO? O, Gasp!
>>
>>
>

Re: TABLE_PER_CLASS does not work as described in JSR-220 (JPA-1.0)

Posted by Serge Bogatyrev <se...@gmail.com>.
I've created an issue: OPENJPA-1096 
<https://issues.apache.org/jira/browse/OPENJPA-1096>

Craig L Russell wrote:
> Hi Serge,
>
> Could you please open a JIRA so we can track this issue?
>
> Thanks,
>
> Craig
>
> On May 11, 2009, at 11:03 AM, Serge Bogatyrev wrote:
>
>> This mixed strategy can be very usefull. But obviously there is 
>> uncompatibility with standards. I think that additional annotation 
>> can be used to change standard behaviour. So, at this example strict 
>> TABLE_PER_CLASS strategy should work without any additional 
>> annotations. And to get the mixed strategy we shoud add @Inheritance 
>> annotation to some class in hierarchy (e.g. AbsractFoo).
>>
>> Pinaki Poddar:
>>> You are right. OpenJPA should use the inheritance strategy used at 
>>> the root
>>> of the hierarchy throughout the derived tree. The extra strategy
>>> specification perhaps is resulting from the facility to support mixed
>>> strategy. Needs further investigation...
>>>
>>>
>>> hallmit wrote:
>>>
>>>> Thanks guys, I put 
>>>> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
>>>> to AbstractFoo and now it works fine...I have also put
>>>> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) to the first
>>>> concrete class of my class hierarchy otherwise the SINGLE_TABLE 
>>>> strategy
>>>> is used for the branch.    
>>>> I thought it was sufficient to annotate the root class with
>>>> TABLE_PER_CLASS and so all classes in the hierarchy would have the 
>>>> same
>>>> strategy...apparently not for OpenJPA...
>>>>
>>>> JSR 220 (JPA-1.0) spec talk :
>>>>
>>>> "The Inheritance annotation defines the inheritance strategy to be 
>>>> used
>>>> for an entity class hierarchy.
>>>> It is specified on the entity class that is the root of the entity 
>>>> class
>>>> hierarchy."
>>>> ...
>>>>     
>>>> In any case thank you very much for your help!
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>> -----
>>> Pinaki Poddar                      http://ppoddar.blogspot.com/
>>>                                      
>>> http://www.linkedin.com/in/pinakipoddar
>>> OpenJPA PMC Member/Committer
>>> JPA Expert Group Member
>>>
>>
>
> Craig L Russell
> Architect, Sun Java Enterprise System http://db.apache.org/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>


Re: TABLE_PER_CLASS does not work as described in JSR-220 (JPA-1.0)

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Serge,

Could you please open a JIRA so we can track this issue?

Thanks,

Craig

On May 11, 2009, at 11:03 AM, Serge Bogatyrev wrote:

> This mixed strategy can be very usefull. But obviously there is  
> uncompatibility with standards. I think that additional annotation  
> can be used to change standard behaviour. So, at this example strict  
> TABLE_PER_CLASS strategy should work without any additional  
> annotations. And to get the mixed strategy we shoud add @Inheritance  
> annotation to some class in hierarchy (e.g. AbsractFoo).
>
> Pinaki Poddar:
>> You are right. OpenJPA should use the inheritance strategy used at  
>> the root
>> of the hierarchy throughout the derived tree. The extra strategy
>> specification perhaps is resulting from the facility to support mixed
>> strategy. Needs further investigation...
>>
>>
>> hallmit wrote:
>>
>>> Thanks guys, I put  
>>> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
>>> to AbstractFoo and now it works fine...I have also put
>>> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) to the first
>>> concrete class of my class hierarchy otherwise the SINGLE_TABLE  
>>> strategy
>>> is used for the branch. 	
>>> I thought it was sufficient to annotate the root class with
>>> TABLE_PER_CLASS and so all classes in the hierarchy would have the  
>>> same
>>> strategy...apparently not for OpenJPA...
>>>
>>> JSR 220 (JPA-1.0) spec talk :
>>>
>>> "The Inheritance annotation defines the inheritance strategy to be  
>>> used
>>> for an entity class hierarchy.
>>> It is specified on the entity class that is the root of the entity  
>>> class
>>> hierarchy."
>>> ...
>>> 	
>>> In any case thank you very much for your help!
>>>
>>>
>>>
>>>
>>
>>
>> -----
>> Pinaki Poddar                      http://ppoddar.blogspot.com/
>>                                      http://www.linkedin.com/in/pinakipoddar
>> OpenJPA PMC Member/Committer
>> JPA Expert Group Member
>>
>

Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: TABLE_PER_CLASS does not work as described in JSR-220 (JPA-1.0)

Posted by Serge Bogatyrev <se...@gmail.com>.
This mixed strategy can be very usefull. But obviously there is 
uncompatibility with standards. I think that additional annotation can 
be used to change standard behaviour. So, at this example strict 
TABLE_PER_CLASS strategy should work without any additional annotations. 
And to get the mixed strategy we shoud add @Inheritance annotation to 
some class in hierarchy (e.g. AbsractFoo).

Pinaki Poddar:
> You are right. OpenJPA should use the inheritance strategy used at the root
> of the hierarchy throughout the derived tree. The extra strategy
> specification perhaps is resulting from the facility to support mixed
> strategy. Needs further investigation...
>
>
> hallmit wrote:
>   
>> Thanks guys, I put @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
>> to AbstractFoo and now it works fine...I have also put
>> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) to the first
>> concrete class of my class hierarchy otherwise the SINGLE_TABLE strategy
>> is used for the branch. 
>> 	
>> I thought it was sufficient to annotate the root class with
>> TABLE_PER_CLASS and so all classes in the hierarchy would have the same
>> strategy...apparently not for OpenJPA...
>>
>> JSR 220 (JPA-1.0) spec talk :
>>
>> "The Inheritance annotation defines the inheritance strategy to be used
>> for an entity class hierarchy.
>> It is specified on the entity class that is the root of the entity class
>> hierarchy."
>> ...
>> 	
>> In any case thank you very much for your help!
>>
>>
>>
>>     
>
>
> -----
> Pinaki Poddar                      http://ppoddar.blogspot.com/
>                                       
> http://www.linkedin.com/in/pinakipoddar
> OpenJPA PMC Member/Committer
> JPA Expert Group Member
>   


Re: TABLE_PER_CLASS does not work as described in JSR-220 (JPA-1.0)

Posted by Pinaki Poddar <pp...@apache.org>.
You are right. OpenJPA should use the inheritance strategy used at the root
of the hierarchy throughout the derived tree. The extra strategy
specification perhaps is resulting from the facility to support mixed
strategy. Needs further investigation...


hallmit wrote:
> 
> Thanks guys, I put @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
> to AbstractFoo and now it works fine...I have also put
> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) to the first
> concrete class of my class hierarchy otherwise the SINGLE_TABLE strategy
> is used for the branch. 
> 	
> I thought it was sufficient to annotate the root class with
> TABLE_PER_CLASS and so all classes in the hierarchy would have the same
> strategy...apparently not for OpenJPA...
> 
> JSR 220 (JPA-1.0) spec talk :
> 
> "The Inheritance annotation defines the inheritance strategy to be used
> for an entity class hierarchy.
> It is specified on the entity class that is the root of the entity class
> hierarchy."
> ...
> 	
> In any case thank you very much for your help!
> 
> 
> 


-----
Pinaki Poddar                      http://ppoddar.blogspot.com/
                                      
http://www.linkedin.com/in/pinakipoddar
OpenJPA PMC Member/Committer
JPA Expert Group Member
-- 
View this message in context: http://n2.nabble.com/TABLE_PER_CLASS-does-not-work-as-described-in-JSR-220-%28JPA-1.0%29-tp2828426p2863155.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: TABLE_PER_CLASS does not work as described in JSR-220 (JPA-1.0)

Posted by hallmit <lf...@genigraph.fr>.
Thanks guys, I put @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) to
AbstractFoo and now it works fine...I have also put
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) to the first concrete
class of my class hierarchy otherwise the SINGLE_TABLE strategy is used for
the branch. 
	
I thought it was sufficient to annotate the root class with TABLE_PER_CLASS
and so all classes in the hierarchy would have the same
strategy...apparently not for OpenJPA...

JSR 220 (JPA-1.0) spec talk :

"The Inheritance annotation defines the inheritance strategy to be used for
an entity class hierarchy.
It is specified on the entity class that is the root of the entity class
hierarchy."
...
	
In any case thank you very much for your help!


-- 
View this message in context: http://n2.nabble.com/TABLE_PER_CLASS-does-not-work-as-described-in-JSR-220-%28JPA-1.0%29-tp2828426p2863129.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: TABLE_PER_CLASS does not work as described in JSR-200 (JPA-1.0)

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
  Add this line to AbstractFoo.

+ @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Entity
abstract AbstractFoo extends RootClass { ...}



-----
Pinaki Poddar                      http://ppoddar.blogspot.com/
                                      
http://www.linkedin.com/in/pinakipoddar
OpenJPA PMC Member/Committer
JPA Expert Group Member
-- 
View this message in context: http://n2.nabble.com/TABLE_PER_CLASS-does-not-work-as-described-in-JSR-200-%28JPA-1.0%29-tp2828426p2845300.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.