persistence@glassfish.java.net

Re: Problem with inheritance...

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Wed, 16 Aug 2006 13:30:36 -0700

Hi Andrei,

Andrei Ilitchev wrote:
> Hi Adam,
>
>
>
> I couldn't reproduce the two problems you described.
>
> Please make sure to use the latest build.
>
> In both cases deploy succeeded, however I ran into another problem in
> one of the cases.
>
>
>
> Details:
>
>
>
> 1. First test: class A is an entity, class B is derived from A and is
> not an entity.
>
> Deploy succeeded; but on attempt to persist an instance of B I got
> StackOverflowError.
>
> Logged the bug https://glassfish.dev.java.net/issues/show_bug.cgi?id=939
>
>
>
> Note that class B shouldn't override setters/getters or access directly
> class A attributes annotated with @OneToOne(fetch=LAZY).
>
> This annotation requires weaving and we don't weave non - entity classes.
>
> Non-woven class B inherits all the weaving from A, so if the limitation
> above is met then B is ok.

This needs to be documented. Right?

thanks,
-marina

>
>
>
> 2. Second test: class A is an entity; class B is derived from A is an
> entity, too. No inheritance annotations on neither of the classes. No pk
> annotations on B.
>
> This scenario worked for me as it was supposed to: inheritance with
> default values is assumed; B uses pk defined in A.
>
>
>
> Thanks,
>
>
>
> Andrei
> ----- Original Message ----- From: "Adam Bien" <abien_at_adam-bien.com>
> To: <persistence_at_glassfish.dev.java.net>
> Cc: <persistence_at_glassfish.dev.java.net>
> Sent: Monday, August 14, 2006 3:28 PM
> Subject: Re: Problem with inheritance...
>
>
>> Hi Andrei,
>>
>> yes you are right. I would like to inherit the persistence capability
>> and not the entity (as "persistent" relationship).
>>
>> The second problem comes from "lazy" loading. It seems to be a bug. It
>> only happens, in case I'm annotating relationships with the
>> FetchType.LAZY...
>>
>> greetings,
>>
>> adam
>> Andrei Ilitchev schrieb:
>>
>>> Hi Adam,
>>>
>>> Here's my understanding of the problem you are experiencing, please
>>> correct me if I am wrong:
>>>
>>> You defined a base Entity class A:
>>> @Entity
>>> @Table(name="A")
>>> public class A implements Serializable {
>>> @Id
>>> @Column(name="ID")
>>> public Integer getId() {
>>> return id;
>>> }
>>> ...
>>> }
>>>
>>> In case you defined derived class B without Entity annotation:
>>> public class B extends A {
>>> ...
>>> }
>>> during deployment you are getting the following exception:
>>>
>>>> Exception [TOPLINK-129] (Oracle TopLink Essentials - 2006.4 (Build
>>>> 060412)): oracle.toplink.essentials.exceptions.DescriptorException
>>>> Exception Description: The set method for the attribute
>>>> [detailRoleName] does not take a ValueHolderInterface as its
>>>> parameter, but the mapping uses indirection.
>>>> Mapping:
>>>> oracle.toplink.essentials.mappings.OneToOneMapping[detailRoleName]
>>>
>>>
>>> Otherwise, if you define the derived class with Entity annotation:
>>> @Entity
>>> public class B extends A {
>>> ...
>>> }
>>> during deployment you are getting exception indicating that B has no
>>> primary key specified
>>>
>>>> (It should define either an @Id, @EmbeddedId or an @IdClass).
>>>
>>>
>>> ----- Original Message ----- From: "Adam Bien" <abien_at_adam-bien.com>
>>> To: <persistence_at_glassfish.dev.java.net>
>>> Cc: <persistence_at_glassfish.dev.java.net>
>>> Sent: Monday, August 14, 2006 12:35 PM
>>> Subject: Problem with inheritance...
>>>
>>>
>>>> Problem/limitation:
>>>>
>>>> I generate entities with annotations (@Id, @Entity) etc.
>>>>
>>>> The coded classes inherit from the generated ones.
>>>> Now I have a problem during deployment:
>>>>
>>>> I get either the exception:
>>>>
>>>> Exception [TOPLINK-129] (Oracle TopLink Essentials - 2006.4 (Build
>>>> 060412)): oracle.toplink.essentials.exceptions.DescriptorException
>>>> Exception Description: The set method for the attribute
>>>> [detailRoleName] does not take a ValueHolderInterface as its
>>>> parameter, but the mapping uses indirection.
>>>> Mapping:
>>>> oracle.toplink.essentials.mappings.OneToOneMapping[detailRoleName]
>>>>
>>>>
>>>> if I mark the concrete-entity as @Entity or:
>>>>
>>>> Test Name : tests.persistence.DefaultProviderVerification
>>>> Test Assertion : Test validity of EJB 3.0 persistence unit. This
>>>> test tests validity using a portable persistence provider. Please
>>>> refer to EJB 3.0 Persistence API Specification for further information.
>>>> Test Description : For [ template#ejb-jar.jar#null ]
>>>> Exception Description: Entity class [class ...EJBSecondDetailBE] has
>>>> no primary key specified. It should define either an @Id,
>>>> @EmbeddedId or an @IdClass.
>>>>
>>>> The primary key is specified, but in the superclass
>>>> (AbstractSecondDetailBE). It seems, like the annotations are not
>>>> "inherited".
>>>>
>>>> thanks and greetings,
>>>>
>>>> adam
>>>>
>>>>
>>>
>>
>>
>> --
>> Dipl. Inf. adam bien
>>
>> BEA Technical Director
>> Sun Certified Java Programmer
>> Sun Certified Enterprise Java Architect Sun Enterprise Java Trainer
>>
>> Mobile: 0049(0)170 280 3144
>> eMail: abien_at_adam-bien.com
>> Homepage: www.adam-bien.com
>> Weblog: http://www.adam-bien.com/roller/page/abien ----------
>> Book author:
>> Enterprise Architekturen
>> entwickler.press 2006
>> ISBN: 393504299X
>>
>> and Enterprise Java Frameworks, J2EE Patterns, J2EE HotSpots and Struts.