[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] EntityManager.find returning instance of wrong type
|
OK, thank you, it seems I had misunderstood how to use the @Inheritance
annotation. However, in this case it does not seem to make a difference
since SINGLE_TABLE is the default inheritance type.
Unfortunately, moving the @Inherintance annotation to the base class did not
solve my problem. EntityManager.find keeps trying to return an instance of
the wrong entity.
Maybe something more I've misunderstood?
tch wrote:
>
> I've never used the @Inheritance annotation, but I believe it goes on
> the base class, not the extending entity.
>
> See:
> http://www.oracle.com/technology/products/ias/toplink/jpa/howto/use-inheritance.html
>
>
>
> On Fri, Mar 6, 2009 at 3:00 AM, jsw <marvin.438@xxxxxxxxx> wrote:
>>
>> Environment: JBoss, Jersey, Spring, EclipseLink JPA, PostgreSQL
>>
>> @Entity
>> public abstract class Base {
>> @Id
>> @GeneratedValue(strategy = GenerationType.TABLE)
>> private Long id;
>>
>> @Version
>> private long version;
>>
>> ...
>> }
>>
>> @Entity
>> @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
>> public class Foo extends Base { ... }
>>
>> @Entity
>> @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
>> public class Bar extends Base { ... }
>>
>> Then when I do:
>>
>> Long aId = 76576; // a valid id for an entity of type Bar
>> Foo foo = em.find(Foo.class, aId); // em is EntityManager
>>
>> an exception is thrown (the root cause seems to be ClassCastException)
>> because the EntityManager tries to return an object of type Bar.
>>
>> What am I doing wrong?
>> --
>> View this message in context:
>> http://www.nabble.com/EntityManager.find-returning-instance-of-wrong-type-tp22367490p22367490.html
>> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>
--
View this message in context: http://www.nabble.com/EntityManager.find-returning-instance-of-wrong-type-tp22367490p22371962.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.