marcos1EM 17 de nov. de 2010
Não entendi direito o que você quis dizer com:
"Eu precisava fazer um select que retornasse pelo menos uma vez os dados, ou seja, nunca poderá retornar mais de uma vez, tipo uma lista. "
Seria fazer uma consulta como SQL ou HQL, por exemplo, que traga um único registro da classe fonte?
Helder8 17 de nov. de 2010
Consegui fazer dessa forma valeu.
Query query = manager . createNamedQuery ( "Fonte.findAll" );
List < Fonte > listaFonte = query . getResultList ();
Mas tenho um problema não consigo converter a lista para Fonte.
Estou fazendo assim:
Fonte fonte = null ;
for ( Fonte listaFonte : getListaFonte ()) {
// Fa ço um verifica ção basica , com o parametro enviado pelo usu ário
if ( listaFonte .getNomeFonte () .equals ( nomeFonte )) {
fonte = listaFonte ;
}
}
D á
ClassCastException , fala que n ão pode converter um Object para Fonte .
O que eu faço???
Obrigado.
Helder
Helder8 17 de nov. de 2010
Dá o seguinte erro
Ocorreu algum erro ao carregar o arquivo . EJB Exception : : java . lang . ClassCastException : [ Ljava . lang . Object ; cannot be cast to geofusion . eti . Fonte at geofusion . util . ImportarBean . fonteImportacao ( ImportarBean . java : 50 ) 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 . bea . core . repackaged . springframework . aop . support . AopUtils . invokeJoinpointUsingReflection ( AopUtils . java : 310 ) at com . bea . core . repackaged . springframework . aop . framework . ReflectiveMethodInvocation . invokeJoinpoint ( ReflectiveMethodInvocation . java : 182 ) at com . bea . core . repackaged . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 149 ) at com . bea . core . repackaged . springframework . aop . support . DelegatingIntroductionInterceptor . doProceed ( DelegatingIntroductionInterceptor . java : 131 ) at com . bea . core . repackaged . springframework . aop . support . DelegatingIntroductionInterceptor . invoke ( DelegatingIntroductionInterceptor . java : 119 ) at com . bea . core . repackaged . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 171 ) at com . bea . core . repackaged . springframework . jee . spi . MethodInvocationVisitorImpl . visit ( MethodInvocationVisitorImpl . java : 37 ) at weblogic . ejb . container . injection . EnvironmentInterceptorCallbackImpl . callback ( EnvironmentInterceptorCallbackImpl . java : 55 ) at com . bea . core . repackaged . springframework . jee . spi . EnvironmentInterceptor . invoke ( EnvironmentInterceptor . java : 50 ) at com . bea . core . repackaged . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 171 ) at com . bea . core . repackaged . springframework . aop . interceptor . ExposeInvocationInterceptor . invoke ( ExposeInvocationInterceptor . java : 89 ) at com . bea . core . repackaged . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 171 ) at com . bea . core . repackaged . springframework . aop . support . DelegatingIntroductionInterceptor . doProceed ( DelegatingIntroductionInterceptor . java : 131 ) at com . bea . core . repackaged . springframework . aop . support . DelegatingIntroductionInterceptor . invoke ( DelegatingIntroductionInterceptor . java : 119 ) at com . bea . core . repackaged . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 171 ) at com . bea . core . repackaged . springframework . aop . framework . JdkDynamicAopProxy . invoke ( JdkDynamicAopProxy . java : 204 ) at $ Proxy153 . fonteImportacao ( Unknown Source ) at geofusion . util . ImportarBean_bj24fo_ImportarImpl . fonteImportacao ( ImportarBean_bj24fo_ImportarImpl . java : 305 ) at geofusion . view . mbean . folheteria . ImportacaoFuncionalidadeMBean_beaVersion0_59 . onImportar ( ImportacaoFuncionalidadeMBean . java : 103 ) at geofusion . view . mbean . folheteria . ImportacaoFuncionalidadeMBean . onImportar ( ImportacaoFuncionalidadeMBean . java ) 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 . el . parser . AstValue . invoke ( AstValue . java : 157 ) at com . sun . el . MethodExpressionImpl . invoke ( MethodExpressionImpl . java : 283 ) at org . apache . myfaces . trinidadinternal . taglib . util . MethodExpressionMethodBinding . invoke ( MethodExpressionMethodBinding . java : 53 ) at org . apache . myfaces . trinidad . component . UIXComponentBase . broadcastToMethodBinding ( UIXComponentBase . java : 1245 ) at org . apache . myfaces . trinidad . component . UIXCommand . broadcast ( UIXCommand . java : 183 ) at oracle . adfinternal . view . faces . lifecycle . LifecycleImpl . broadcastEvents ( LifecycleImpl . java : 812 ) at oracle . adfinternal . view . faces . lifecycle . LifecycleImpl . _executePhase ( LifecycleImpl . java : 292 ) at oracle . adfinternal . view . faces . lifecycle . LifecycleImpl . execute ( LifecycleImpl . java : 177 ) at javax . faces . webapp . FacesServlet . service ( FacesServlet . java : 265 ) at weblogic . servlet . internal . StubSecurityHelper $ ServletServiceAction . run ( StubSecurityHelper . java : 227 ) at weblogic . servlet . internal . StubSecurityHelper . invokeServlet ( StubSecurityHelper . java : 125 ) at weblogic . servlet . internal . ServletStubImpl . execute ( ServletStubImpl . java : 292 ) at weblogic . servlet . internal . TailFilter . doFilter ( TailFilter . java : 26 ) at weblogic . servlet . internal . FilterChainImpl . doFilter ( FilterChainImpl . java : 56 ) at oracle . adf . model . servlet . ADFBindingFilter . doFilter ( ADFBindingFilter . java : 191 ) at weblogic . servlet . internal . FilterChainImpl . doFilter ( FilterChainImpl . java : 56 ) at oracle . adfinternal . view . faces . webapp . rich . RegistrationFilter . doFilter ( RegistrationFilter . java : 97 ) at org . apache . myfaces . trinidadinternal . webapp . TrinidadFilterImpl $ FilterListChain . doFilter ( TrinidadFilterImpl . java : 420 ) at oracle . adfinternal . view . faces . activedata . AdsFilter . doFilter ( AdsFilter . java : 60 ) at org . apache . myfaces . trinidadinternal . webapp . TrinidadFilterImpl $ FilterListChain . doFilter ( TrinidadFilterImpl . java : 420 ) at org . apache . myfaces . trinidadinternal . webapp . TrinidadFilterImpl . _doFilterImpl ( TrinidadFilterImpl . java : 247 ) at org . apache . myfaces . trinidadinternal . webapp . TrinidadFilterImpl . doFilter ( TrinidadFilterImpl . java : 157 ) at org . apache . myfaces . trinidad . webapp . TrinidadFilter . doFilter ( TrinidadFilter . java : 92 ) at weblogic . servlet . internal . FilterChainImpl . doFilter ( FilterChainImpl . java : 56 ) at oracle . security . jps . ee . http . JpsAbsFilter $ 1 . run ( JpsAbsFilter . java : 94 ) at java . security . AccessController . doPrivileged ( Native Method ) at oracle . security . jps . util . JpsSubject . doAsPrivileged ( JpsSubject . java : 313 ) at oracle . security . jps . ee . util . JpsPlatformUtil . runJaasMode ( JpsPlatformUtil . java : 413 ) at oracle . security . jps . ee . http . JpsAbsFilter . doFilter ( JpsAbsFilter . java : 138 ) at oracle . security . jps . ee . http . JpsFilter . doFilter ( JpsFilter . java : 70 ) at weblogic . servlet . internal . FilterChainImpl . doFilter ( FilterChainImpl . java : 56 ) at weblogic . servlet . internal . RequestDispatcherImpl . invokeServlet ( RequestDispatcherImpl . java : 500 ) at weblogic . servlet . internal . RequestDispatcherImpl . forward ( RequestDispatcherImpl . java : 248 ) at geofusion . adf . util . JSFUtils_beaVersion0_60 . forward ( JSFUtils . java : 364 ) at geofusion . adf . util . JSFUtils . forward ( JSFUtils . java ) at geofusion . view . filtro . SessaoUsuarioFilter_beaVersion0_8 . doFilter ( SessaoUsuarioFilter . java : 87 ) at geofusion . view . filtro . SessaoUsuarioFilter . doFilter ( SessaoUsuarioFilter . java ) at weblogic . servlet . internal . FilterChainImpl . doFilter ( FilterChainImpl . java : 56 ) at weblogic . servlet . utils . FastSwapFilter . doFilter ( FastSwapFilter . java : 66 ) at weblogic . servlet . internal . FilterChainImpl . doFilter ( FilterChainImpl . java : 56 ) at oracle . dms . wls . DMSServletFilter . doFilter ( DMSServletFilter . java : 326 ) at weblogic . servlet . internal . FilterChainImpl . doFilter ( FilterChainImpl . java : 56 ) at weblogic . servlet . internal . RequestEventsFilter . doFilter ( RequestEventsFilter . java : 27 ) at weblogic . servlet . internal . FilterChainImpl . doFilter ( FilterChainImpl . java : 56 ) at weblogic . servlet . internal . WebAppServletContext $ ServletInvocationAction . run ( WebAppServletContext . java : 3592 ) at weblogic . security . acl . internal . AuthenticatedSubject . doAs ( AuthenticatedSubject . java : 321 ) at weblogic . security . service . SecurityManager . runAs ( SecurityManager . java : 121 ) at weblogic . servlet . internal . WebAppServletContext . securedExecute ( WebAppServletContext . java : 2202 ) at weblogic . servlet . internal . WebAppServletContext . execute ( WebAppServletContext . java : 2108 ) at weblogic . servlet . internal . ServletRequestImpl . run ( ServletRequestImpl . java : 1432 ) at weblogic . work . ExecuteThread . execute ( ExecuteThread . java : 201 ) at weblogic . work . ExecuteThread . run ( ExecuteThread . java : 173 ) ; nested exception is : java . lang . ClassCastException : [ Ljava . lang . Object ; cannot be cast to geofusion . eti . Fonte
Helder8 18 de nov. de 2010
Resolvi.
Como eu estava usando o JDeveloper, ele estava se perdendo, mas o que eu fiz acima estava certinho.
Solução simples para problema simples:
=> Eu apenas fechei o JDeveloper e abri novamente e funcionou.
Valeu,
Helder