Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] EntityManager.find returning instance of wrong type

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
>


Back to the top