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 don't understand why JPA is searching through objects of type Bar when I
specifically ask for an object of type Foo. I would expect JPA to notice
that the type does not match even though the id does and return null instead
of simply trying to cast. (Or better yet, not bother to sift through objects
of the wrong type.) Somebody might be trying to do what I did ;-)




Zarar Siddiqi wrote:
> 
> I really don't see what the "odd" part about this behavior is.
> 
> The reason that em.find(Foo.class, barId) is throwing a
> ClassCastException is because you're returning a Bar object while
> telling JPA that you're expecting a Foo.  So JPA (like the innocent
> child that it is) while get your object and try to cast it to Foo
> because you told it to do so by passing in Foo.class into the
> em.find().
> 
> I'm not sure what you're expecting.
> 
> 
> On Sun, Mar 8, 2009 at 11:09 AM, jsw <marvin.438@xxxxxxxxx> wrote:
>>
>> Yes, a workaround would be
>>
>>  Base b = em.find(Base.class, id);
>>
>>  if (b instanceof Foo) {
>>     doStuffToFoo((Foo) b);
>>  else if (b instanceof Bar) {
>>     doStuffToBar((Bar) b);
>>  }
>>
>> However, I think it is odd behavior that an object of the wrong type is
>> returned. Can anyone tell me if this really is "by design"?
>>
>>
>>
>> Zarar Siddiqi wrote:
>>>
>>> If that's what your goal is then your findBarById should look something
>>> like:
>>>
>>> Object obj = em.find(Bar.class, aId);
>>>
>>> if (obj instanceof Bar)
>>>    return (Bar) obj;
>>> else
>>>   return null;
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Sun, Mar 8, 2009 at 10:57 AM, jsw <marvin.438@xxxxxxxxx> wrote:
>>>>
>>>> I get an id of an entity of either Foo or Bar type as input. So I try
>>>> to
>>>> determine the type by searching for
>>>> both, like so:
>>>>
>>>> public void doStuff(Long id) {
>>>>  Base base = null;
>>>>  if ((base = this.facade.getDAO().findFooById(id)) != null) { // this
>>>> row
>>>> will throw an exception
>>>>      log.debug("Found Foo");
>>>>      doStuffToFoo((Foo) base);
>>>>  } else if ((base = this.facade.getDAO().findBarById(id)) != null) {
>>>>      log.debug("Found Bar");
>>>>      doStuffToBar((Bar) base);
>>>>  }
>>>> }
>>>>
>>>> I don't think the entity manager should ever return an entity of other
>>>> type
>>>> than the requested. IMHO, if no entity of the requested type exists
>>>> with
>>>> the
>>>> specified id, the logical thing to return would be null (or perhaps an
>>>> exception).
>>>>
>>>>
>>>>
>>>> Zarar Siddiqi wrote:
>>>>>
>>>>> Also, just looking at the code sample you provided:
>>>>>
>>>>>    Long aId = 76576; // a valid id for an entity of type Bar
>>>>>    Foo foo = em.find(Foo.class, aId); // em is EntityManager
>>>>>
>>>>> Why would you not just do the following if you're expecting a Bar
>>>>> object:
>>>>>
>>>>> Bar bar = em.find(Bar.class, aId);
>>>>>
>>>>> ??  I think the ClassCastException that you're getting is the right
>>>>> behaviour.
>>>>>
>>>>>
>>>>>
>>>>> On Sun, Mar 8, 2009 at 10:36 AM, Zarar Siddiqi <zarars@xxxxxxxxx>
>>>>> wrote:
>>>>>> Currently you've got
>>>>>> @Inheritance(strategy=InheritanceType.SINGLE_TABLE) on the
>>>>>> subclasses,
>>>>>> try putting them ONLY on the base class.
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Sun, Mar 8, 2009 at 6:50 AM, jsw <marvin.438@xxxxxxxxx> wrote:
>>>>>>>
>>>>>>> If I've understood correctly, when the DiscriminatorColumn
>>>>>>> annotation
>>>>>>> is
>>>>>>> missing JPA defaults to DTYPE (with values corresponding to the
>>>>>>> entity
>>>>>>> name). Just to be sure I tried adding the DiscriminatorColumn
>>>>>>> annotation
>>>>>>> to
>>>>>>> the Base class and DiscriminatorValue annotations to the subclasses
>>>>>>> (I
>>>>>>> had
>>>>>>> already moved the Inheritance from the deriving clases to the Base
>>>>>>> class)
>>>>>>> but it made no difference: the problem persists.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Zarar Siddiqi wrote:
>>>>>>>>
>>>>>>>> How would JPA know what row coincides with what subclass?  To tell
>>>>>>>> it
>>>>>>>> that you'll need to use the @DiscriminatorColumn on the parent
>>>>>>>> class
>>>>>>>> and supply a unique value for each subclass using the
>>>>>>>> @DiscriminatorValue for the subclasses.
>>>>>>>>
>>>>>>>> Also, the @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
>>>>>>>> annotation goes on the parent class.
>>>>>>>>
>>>>>>>> Zarar
>>>>>>>>
>>>>>>>>
>>>>>>>> On Fri, Mar 6, 2009 at 8:52 AM, jsw <marvin.438@xxxxxxxxx> wrote:
>>>>>>>>>
>>>>>>>>> In my REST service:
>>>>>>>>>
>>>>>>>>>  public void doTest() {
>>>>>>>>>        long id = 12; // valid id of Bar entity
>>>>>>>>>
>>>>>>>>>        List<Base> bases = this.facade.getDAO().findAllBase();
>>>>>>>>>
>>>>>>>>>        Base base = null;
>>>>>>>>>        try {
>>>>>>>>>            if ((base =
>>>>>>>>> this.facade.getWorkOrderDAO().findFooById(id))
>>>>>>>>> !=
>>>>>>>>> null) { // this row will throw an exception
>>>>>>>>>                log.debug("Found Foo");
>>>>>>>>>            } else if ((base =
>>>>>>>>> this.facade.getWorkOrderDAO().findBarById(id)) != null) {
>>>>>>>>>                log.debug("Found Bar");
>>>>>>>>>            }
>>>>>>>>>
>>>>>>>>>        } catch (Exception ex) {
>>>>>>>>>            ex.printStackTrace();
>>>>>>>>>        }
>>>>>>>>>  }
>>>>>>>>>
>>>>>>>>> And in the DAO class:
>>>>>>>>>
>>>>>>>>>    @Transactional(readOnly = true,
>>>>>>>>> propagation=Propagation.SUPPORTS)
>>>>>>>>>    public List<Base> findAllBase() {
>>>>>>>>>        return em.createQuery("select b from Base
>>>>>>>>> b").getResultList();
>>>>>>>>>    }
>>>>>>>>>
>>>>>>>>>    @Transactional(readOnly = true,
>>>>>>>>> propagation=Propagation.SUPPORTS)
>>>>>>>>>    public Foo findFooById(long id) {
>>>>>>>>>        return em.find(Foo.class, id);
>>>>>>>>>    }
>>>>>>>>>
>>>>>>>>>    @Transactional(readOnly = true,
>>>>>>>>> propagation=Propagation.SUPPORTS)
>>>>>>>>>    public Bar findBarById(long id) {
>>>>>>>>>        return em.find(Bar.class, id);
>>>>>>>>>    }
>>>>>>>>>
>>>>>>>>> java.lang.ClassCastException:
>>>>>>>>> com.acme.planning.dataaccess.model.Bar
>>>>>>>>> cannot
>>>>>>>>> be cast to com.acme.planning.dataaccess.model.Foo
>>>>>>>>>     at com.acme.planning.dataaccess.DAO.findFooById(DAO.java:348)
>>>>>>>>>     at
>>>>>>>>> com.acme.planning.dataaccess.DAO$$FastClassByCGLIB$$80c0e135.invoke(<generated>)
>>>>>>>>>     at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
>>>>>>>>>     at
>>>>>>>>> org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
>>>>>>>>>     at
>>>>>>>>> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
>>>>>>>>>     at
>>>>>>>>> org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
>>>>>>>>>     at
>>>>>>>>> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
>>>>>>>>>     at
>>>>>>>>> org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
>>>>>>>>>     at
>>>>>>>>> com.acme.planning.dataaccess.DAO$$EnhancerByCGLIB$$93a24725.findFooById(<generated>)
>>>>>>>>>     at
>>>>>>>>> com.acme.planning.interaction.rest.MobilogService.test(MobilogService.java:829)
>>>>>>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>>>>>>     at
>>>>>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>>>>>>     at
>>>>>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>>>>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$ResponseOutInvoker._dispatch(EntityParamDispatchProvider.java:157)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:154)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:63)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:543)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:502)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:493)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:308)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:314)
>>>>>>>>>     at
>>>>>>>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:239)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>>>>>>>>>     at
>>>>>>>>> com.acme.common.filter.CacheControlFilter.doFilter(CacheControlFilter.java:72)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:174)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:277)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>>>>>>>>>     at
>>>>>>>>> org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175)
>>>>>>>>>     at
>>>>>>>>> org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
>>>>>>>>>     at
>>>>>>>>> org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>>>>>>>>>     at
>>>>>>>>> org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
>>>>>>>>>     at
>>>>>>>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>>>>>>>>>     at
>>>>>>>>> org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
>>>>>>>>>     at
>>>>>>>>> org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
>>>>>>>>>     at
>>>>>>>>> org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>>>>>>>>>     at
>>>>>>>>> org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>>>>>>>>>     at
>>>>>>>>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
>>>>>>>>>     at
>>>>>>>>> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
>>>>>>>>>     at
>>>>>>>>> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
>>>>>>>>>     at
>>>>>>>>> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
>>>>>>>>>     at java.lang.Thread.run(Thread.java:619)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> tch wrote:
>>>>>>>>>>
>>>>>>>>>> Doesn't sound right, can you post the whole stack trace?
>>>>>>>>>>
>>>>>>>>>> ./tch
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Fri, Mar 6, 2009 at 7:56 AM, jsw <marvin.438@xxxxxxxxx> wrote:
>>>>>>>>>>>
>>>>>>>>>>> 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.
>>>>>>>>>>>
>>>>>>>>>>> _______________________________________________
>>>>>>>>>>> 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-tp22367490p22372894.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-tp22367490p22396645.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-tp22367490p22398821.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-tp22367490p22398946.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-tp22367490p22399501.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top