dreampeppers99 24 de jul. de 2011
Tente:
1 - Adicionar mais uma anotação a seu Dao
@Repository
DAOGenericoImpl
2 - Deixe o get e set para EntityManager sem as verificações de nualidade. (tire as condições do getEntityManager()).
EuclidesFilizola 24 de jul. de 2011
Boa tarde,
ao colocar o @Repository no daogenericImpl ,me veio esse erro:
SEVERE : Exception sending context initialized event to listener instance of class org . springframework . web . context . ContextLoaderListener
org . springframework . beans . factory . BeanCreationException : Error creating bean with name 'DAOGenericoImpl' defined in file [ C : \Users \Administrador \workspace \. metadata \. plugins \org . eclipse . wst . server . core \tmp0 \wtpwebapps \BancoFic \WEB - INF \classes \br \com \fic \bancoFic \dao \DAOGenericoImpl . class ]: Instantiation of bean failed ; nested exception is org . springframework . beans . BeanInstantiationException : Could not instantiate bean class [ br . com . fic . bancoFic . dao . DAOGenericoImpl ]: Constructor threw exception ; nested exception is java . lang . ClassCastException : java . lang . Class cannot be cast to java . lang . reflect . ParameterizedType
at org . springframework . beans . factory . support . AbstractAutowireCapableBeanFactory . instantiateBean ( AbstractAutowireCapableBeanFactory . java : 883 )
at org . springframework . beans . factory . support . AbstractAutowireCapableBeanFactory . createBeanInstance ( AbstractAutowireCapableBeanFactory . java : 839 )
at org . springframework . beans . factory . support . AbstractAutowireCapableBeanFactory . doCreateBean ( AbstractAutowireCapableBeanFactory . java : 440 )
at org . springframework . beans . factory . support . AbstractAutowireCapableBeanFactory $ 1. run ( AbstractAutowireCapableBeanFactory . java : 409 )
at java . security . AccessController . doPrivileged ( Native Method )
at org . springframework . beans . factory . support . AbstractAutowireCapableBeanFactory . createBean ( AbstractAutowireCapableBeanFactory . java : 380 )
at org . springframework . beans . factory . support . AbstractBeanFactory $ 1. getObject ( AbstractBeanFactory . java : 264 )
at org . springframework . beans . factory . support . DefaultSingletonBeanRegistry . getSingleton ( DefaultSingletonBeanRegistry . java : 221 )
at org . springframework . beans . factory . support . AbstractBeanFactory . doGetBean ( AbstractBeanFactory . java : 261 )
at org . springframework . beans . factory . support . AbstractBeanFactory . getBean ( AbstractBeanFactory . java : 185 )
at org . springframework . beans . factory . support . AbstractBeanFactory . getBean ( AbstractBeanFactory . java : 164 )
at org . springframework . beans . factory . support . DefaultListableBeanFactory . preInstantiateSingletons ( DefaultListableBeanFactory . java : 429 )
at org . springframework . context . support . AbstractApplicationContext . finishBeanFactoryInitialization ( AbstractApplicationContext . java : 729 )
at org . springframework . context . support . AbstractApplicationContext . refresh ( AbstractApplicationContext . java : 381 )
at org . springframework . web . context . ContextLoader . createWebApplicationContext ( ContextLoader . java : 255 )
at org . springframework . web . context . ContextLoader . initWebApplicationContext ( ContextLoader . java : 199 )
at org . springframework . web . context . ContextLoaderListener . contextInitialized ( ContextLoaderListener . java : 45 )
at org . apache . catalina . core . StandardContext . listenerStart ( StandardContext . java : 4205 )
at org . apache . catalina . core . StandardContext . start ( StandardContext . java : 4704 )
at org . apache . catalina . core . ContainerBase . start ( ContainerBase . java : 1053 )
at org . apache . catalina . core . StandardHost . start ( StandardHost . java : 840 )
at org . apache . catalina . core . ContainerBase . start ( ContainerBase . java : 1053 )
at org . apache . catalina . core . StandardEngine . start ( StandardEngine . java : 463 )
at org . apache . catalina . core . StandardService . start ( StandardService . java : 525 )
at org . apache . catalina . core . StandardServer . start ( StandardServer . java : 754 )
at org . apache . catalina . startup . Catalina . start ( Catalina . java : 595 )
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 org . apache . catalina . startup . Bootstrap . start ( Bootstrap . java : 289 )
at org . apache . catalina . startup . Bootstrap . main ( Bootstrap . java : 414 )
Caused by : org . springframework . beans . BeanInstantiationException : Could not instantiate bean class [ br . com . fic . bancoFic . dao . DAOGenericoImpl ]: Constructor threw exception ; nested exception is java . lang . ClassCastException : java . lang . Class cannot be cast to java . lang . reflect . ParameterizedType
at org . springframework . beans . BeanUtils . instantiateClass ( BeanUtils . java : 115 )
at org . springframework . beans . factory . support . SimpleInstantiationStrategy . instantiate ( SimpleInstantiationStrategy . java : 61 )
at org . springframework . beans . factory . support . AbstractAutowireCapableBeanFactory . instantiateBean ( AbstractAutowireCapableBeanFactory . java : 877 )
... 31 more
Caused by : java . lang . ClassCastException : java . lang . Class cannot be cast to java . lang . reflect . ParameterizedType
at br . com . fic . bancoFic . dao . DAOGenericoImpl .& lt ; init & gt ;( DAOGenericoImpl . java : 26 )
at sun . reflect . NativeConstructorAccessorImpl . newInstance0 ( Native Method )
at sun . reflect . NativeConstructorAccessorImpl . newInstance ( NativeConstructorAccessorImpl . java : 39 )
at sun . reflect . DelegatingConstructorAccessorImpl . newInstance ( DelegatingConstructorAccessorImpl . java : 27 )
at java . lang . reflect . Constructor . newInstance ( Constructor . java : 513 )
at org . springframework . beans . BeanUtils . instantiateClass ( BeanUtils . java : 100 )
... 33 more
24 / Jul / 2011 17 : 44 : 37 com . sun . faces . config . ConfigureListener contextInitialized
INFO : Initializing Mojarra ( 1.2 _10 - b01 - FCS ) for context '/BancoFic'
24 / Jul / 2011 17 : 44 : 38 org . apache . catalina . core . StandardContext start
SEVERE : Error listenerStart
24 / Jul / 2011 17 : 44 : 38 org . apache . catalina . core . StandardContext start
SEVERE : Context [ / BancoFic ] startup failed due to previous errors
24 / Jul / 2011 17 : 44 : 38 org . apache . catalina . core . ApplicationContext log
INFO : Closing Spring root WebApplicationContext
24 / Jul / 2011 17 : 44 : 38 org . apache . catalina . loader . WebappClassLoader clearReferencesJdbc
SEVERE : The web application [ / BancoFic ] registered the JDBC driver [ com . mysql . jdbc . Driver ] but failed to unregister it when the web application was stopped . To prevent a memory leak , the JDBC Driver has been forcibly unregistered .
24 / Jul / 2011 17 : 44 : 39 org . apache . coyote . http11 . Http11Protocol start
INFO : Starting Coyote HTTP / 1.1 on http - 8080
24 / Jul / 2011 17 : 44 : 39 org . apache . jk . common . ChannelSocket init
INFO : JK : ajp13 listening on / 0.0 . 0.0 : 8009
24 / Jul / 2011 17 : 44 : 39 org . apache . jk . server . JkMain start
INFO : Jk running ID = 0 time = 0 / 31 config = null
24 / Jul / 2011 17 : 44 : 39 org . apache . catalina . startup . Catalina start
INFO : Server startup in 5901 ms
e aqui está a minha classe daoGenerico.
package br.com.fic.bancoFic.dao ;
import java.io.Serializable ;
import java.lang.reflect.ParameterizedType ;
import java.util.List ;
import javax.persistence.EntityManager ;
import javax.persistence.PersistenceContext ;
import org.springframework.stereotype.Repository ;
import org.springframework.transaction.annotation.Propagation ;
import org.springframework.transaction.annotation.Transactional ;
@Repository
@Transactional ( readOnly = true , propagation = Propagation . REQUIRED )
public class DAOGenericoImpl & lt ; T , ID extends Serializable & gt ; implements DAOGenerico & lt ; T , ID & gt ; {
@PersistenceContext
private EntityManager entityManager ;
private final Class & lt ; T & gt ; oClass ;
@SuppressWarnings ( "unchecked" )
public DAOGenericoImpl () {
this . oClass = ( Class & lt ; T & gt ;) (( ParameterizedType ) getClass (). getGenericSuperclass ()). getActualTypeArguments () [ 0 ] ;
}
public Class & lt ; T & gt ; getObjectClass (){
return this . oClass ;
}
@Override
@Transactional ( readOnly = false , propagation = Propagation . REQUIRED )
public T salvar ( T object ) {
getEntityManager (). clear ();
getEntityManager (). persist ( object );
return object ;
}
@Override
public T pesquisarPorId ( Serializable id ) {
return ( T ) getEntityManager (). find ( oClass , id );
}
@Override
@Transactional ( readOnly = false , propagation = Propagation . REQUIRED )
public T atualizar ( T object ) {
getEntityManager (). merge ( object );
return object ;
}
@Override
@Transactional ( readOnly = false , propagation = Propagation . REQUIRED )
public void excluir ( T object ) {
object = getEntityManager (). merge ( object );
getEntityManager (). remove ( object );
}
@Override
public List & lt ; T & gt ; todos () {
return null ;
}
public void setEntityManager ( EntityManager em ) {
this . entityManager = em ;
}
public EntityManager getEntityManager () {
/*if(entityManager == null)
throw new IllegalStateException("Erro");
*/
return entityManager ;
}
}
dreampeppers99 24 de jul. de 2011
java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
Erro parece estar ocorrendo porque o spring não consegue criar o objeto sem tipo espcificado (seu generico)
Esse @repository tem que ficar na classe subclasse do seu dao generico
seu dao generico deveria ser abstrato
e por exemplo ter
@Repositorio
public class PessoaDao extends DAOGenericoImpl<Pessoa,Long> {
}
EuclidesFilizola 24 de jul. de 2011
então continua tudo no mesmo.
o meu dao já tem isso
@ Repository
@ Transactional
public interface ContaDAO extends DAOGenerico & lt ; ContaBancaria , Integer & gt ; {
}
dreampeppers99 24 de jul. de 2011
ja removeu o @repository do DaoGenericImpl?
EuclidesFilizola 24 de jul. de 2011
EuclidesFilizola 24 de jul. de 2011
e o erro persiste.
SEVERE : java . lang . NullPointerException
javax . faces . el . EvaluationException : java . lang . NullPointerException
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 102 )
at com . sun . faces . application . ActionListenerImpl . processAction ( ActionListenerImpl . java : 102 )
at javax . faces . component . UICommand . broadcast ( UICommand . java : 387 )
at org . ajax4jsf . component . AjaxViewRoot . processEvents ( AjaxViewRoot . java : 321 )
at org . ajax4jsf . component . AjaxViewRoot . broadcastEvents ( AjaxViewRoot . java : 296 )
at org . ajax4jsf . component . AjaxViewRoot . processPhase ( AjaxViewRoot . java : 253 )
at org . ajax4jsf . component . AjaxViewRoot . processApplication ( AjaxViewRoot . java : 466 )
at com . sun . faces . lifecycle . InvokeApplicationPhase . execute ( InvokeApplicationPhase . java : 82 )
at com . sun . faces . lifecycle . Phase . doPhase ( Phase . java : 100 )
at com . sun . faces . lifecycle . LifecycleImpl . execute ( LifecycleImpl . java : 118 )
at javax . faces . webapp . FacesServlet . service ( FacesServlet . java : 265 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . ajax4jsf . webapp . BaseXMLFilter . doXmlFilter ( BaseXMLFilter . java : 178 )
at org . ajax4jsf . webapp . BaseFilter . handleRequest ( BaseFilter . java : 290 )
at org . ajax4jsf . webapp . BaseFilter . processUploadsAndHandleRequest ( BaseFilter . java : 390 )
at org . ajax4jsf . webapp . BaseFilter . doFilter ( BaseFilter . java : 517 )
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 : 233 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 191 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 127 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 102 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 109 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 298 )
at org . apache . coyote . http11 . Http11Processor . process ( Http11Processor . java : 859 )
at org . apache . coyote . http11 . Http11Protocol $ Http11ConnectionHandler . process ( Http11Protocol . java : 588 )
at org . apache . tomcat . util . net . JIoEndpoint $ Worker . run ( JIoEndpoint . java : 489 )
at java . lang . Thread . run ( Unknown Source )
Caused by : java . lang . NullPointerException
at br . com . fic . bancoFic . dao . ContaDAOImp . verificarExistenciaConta ( ContaDAOImp . java : 22 )
at br . com . fic . bancoFic . negocio . ContaNegocio . verificarConta ( ContaNegocio . java : 19 )
at br . com . fic . bancoFic . mBeans . ContaBancariaBean . verificarConta ( ContaBancariaBean . java : 28 )
at sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
at sun . reflect . NativeMethodAccessorImpl . invoke ( Unknown Source )
at sun . reflect . DelegatingMethodAccessorImpl . invoke ( Unknown Source )
at java . lang . reflect . Method . invoke ( Unknown Source )
at org . apache . el . parser . AstValue . invoke ( AstValue . java : 191 )
at org . apache . el . MethodExpressionImpl . invoke ( MethodExpressionImpl . java : 276 )
at com . sun . facelets . el . TagMethodExpression . invoke ( TagMethodExpression . java : 68 )
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 88 )
... 28 more
24 / Jul / 2011 19 : 02 : 57 com . sun . faces . lifecycle . InvokeApplicationPhase execute
WARNING : #{contaBancariaBean.verificarConta}: java.lang.NullPointerException
javax . faces . FacesException : #{contaBancariaBean.verificarConta}: java.lang.NullPointerException
at com . sun . faces . application . ActionListenerImpl . processAction ( ActionListenerImpl . java : 118 )
at javax . faces . component . UICommand . broadcast ( UICommand . java : 387 )
at org . ajax4jsf . component . AjaxViewRoot . processEvents ( AjaxViewRoot . java : 321 )
at org . ajax4jsf . component . AjaxViewRoot . broadcastEvents ( AjaxViewRoot . java : 296 )
at org . ajax4jsf . component . AjaxViewRoot . processPhase ( AjaxViewRoot . java : 253 )
at org . ajax4jsf . component . AjaxViewRoot . processApplication ( AjaxViewRoot . java : 466 )
at com . sun . faces . lifecycle . InvokeApplicationPhase . execute ( InvokeApplicationPhase . java : 82 )
at com . sun . faces . lifecycle . Phase . doPhase ( Phase . java : 100 )
at com . sun . faces . lifecycle . LifecycleImpl . execute ( LifecycleImpl . java : 118 )
at javax . faces . webapp . FacesServlet . service ( FacesServlet . java : 265 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . ajax4jsf . webapp . BaseXMLFilter . doXmlFilter ( BaseXMLFilter . java : 178 )
at org . ajax4jsf . webapp . BaseFilter . handleRequest ( BaseFilter . java : 290 )
at org . ajax4jsf . webapp . BaseFilter . processUploadsAndHandleRequest ( BaseFilter . java : 390 )
at org . ajax4jsf . webapp . BaseFilter . doFilter ( BaseFilter . java : 517 )
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 : 233 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 191 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 127 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 102 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 109 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 298 )
at org . apache . coyote . http11 . Http11Processor . process ( Http11Processor . java : 859 )
at org . apache . coyote . http11 . Http11Protocol $ Http11ConnectionHandler . process ( Http11Protocol . java : 588 )
at org . apache . tomcat . util . net . JIoEndpoint $ Worker . run ( JIoEndpoint . java : 489 )
at java . lang . Thread . run ( Unknown Source )
Caused by : javax . faces . el . EvaluationException : java . lang . NullPointerException
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 102 )
at com . sun . faces . application . ActionListenerImpl . processAction ( ActionListenerImpl . java : 102 )
... 27 more
Caused by : java . lang . NullPointerException
at br . com . fic . bancoFic . dao . ContaDAOImp . verificarExistenciaConta ( ContaDAOImp . java : 22 )
at br . com . fic . bancoFic . negocio . ContaNegocio . verificarConta ( ContaNegocio . java : 19 )
at br . com . fic . bancoFic . mBeans . ContaBancariaBean . verificarConta ( ContaBancariaBean . java : 28 )
at sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
at sun . reflect . NativeMethodAccessorImpl . invoke ( Unknown Source )
at sun . reflect . DelegatingMethodAccessorImpl . invoke ( Unknown Source )
at java . lang . reflect . Method . invoke ( Unknown Source )
at org . apache . el . parser . AstValue . invoke ( AstValue . java : 191 )
at org . apache . el . MethodExpressionImpl . invoke ( MethodExpressionImpl . java : 276 )
at com . sun . facelets . el . TagMethodExpression . invoke ( TagMethodExpression . java : 68 )
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 88 )
... 28 more
24 / Jul / 2011 19 : 02 : 57 com . sun . faces . lifecycle . Phase doPhase
SEVERE : JSF1054 : ( Phase ID : INVOKE_APPLICATION 5 , View ID : / login . xhtml ) Exception thrown during phase execution : javax . faces . event . PhaseEvent [ source = com . sun . faces . lifecycle . LifecycleImpl @ ae43b8 ]
24 / Jul / 2011 19 : 02 : 57 org . apache . catalina . core . StandardWrapperValve invoke
SEVERE : Servlet . service () for servlet Faces Servlet threw exception
java . lang . NullPointerException
at br . com . fic . bancoFic . dao . ContaDAOImp . verificarExistenciaConta ( ContaDAOImp . java : 22 )
at br . com . fic . bancoFic . negocio . ContaNegocio . verificarConta ( ContaNegocio . java : 19 )
at br . com . fic . bancoFic . mBeans . ContaBancariaBean . verificarConta ( ContaBancariaBean . java : 28 )
at sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
at sun . reflect . NativeMethodAccessorImpl . invoke ( Unknown Source )
at sun . reflect . DelegatingMethodAccessorImpl . invoke ( Unknown Source )
at java . lang . reflect . Method . invoke ( Unknown Source )
at org . apache . el . parser . AstValue . invoke ( AstValue . java : 191 )
at org . apache . el . MethodExpressionImpl . invoke ( MethodExpressionImpl . java : 276 )
at com . sun . facelets . el . TagMethodExpression . invoke ( TagMethodExpression . java : 68 )
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 88 )
at com . sun . faces . application . ActionListenerImpl . processAction ( ActionListenerImpl . java : 102 )
at javax . faces . component . UICommand . broadcast ( UICommand . java : 387 )
at org . ajax4jsf . component . AjaxViewRoot . processEvents ( AjaxViewRoot . java : 321 )
at org . ajax4jsf . component . AjaxViewRoot . broadcastEvents ( AjaxViewRoot . java : 296 )
at org . ajax4jsf . component . AjaxViewRoot . processPhase ( AjaxViewRoot . java : 253 )
at org . ajax4jsf . component . AjaxViewRoot . processApplication ( AjaxViewRoot . java : 466 )
at com . sun . faces . lifecycle . InvokeApplicationPhase . execute ( InvokeApplicationPhase . java : 82 )
at com . sun . faces . lifecycle . Phase . doPhase ( Phase . java : 100 )
at com . sun . faces . lifecycle . LifecycleImpl . execute ( LifecycleImpl . java : 118 )
at javax . faces . webapp . FacesServlet . service ( FacesServlet . java : 265 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . ajax4jsf . webapp . BaseXMLFilter . doXmlFilter ( BaseXMLFilter . java : 178 )
at org . ajax4jsf . webapp . BaseFilter . handleRequest ( BaseFilter . java : 290 )
at org . ajax4jsf . webapp . BaseFilter . processUploadsAndHandleRequest ( BaseFilter . java : 390 )
at org . ajax4jsf . webapp . BaseFilter . doFilter ( BaseFilter . java : 517 )
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 : 233 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 191 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 127 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 102 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 109 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 298 )
at org . apache . coyote . http11 . Http11Processor . process ( Http11Processor . java : 859 )
at org . apache . coyote . http11 . Http11Protocol $ Http11ConnectionHandler . process ( Http11Protocol . java : 588 )
at org . apache . tomcat . util . net . JIoEndpoint $ Worker . run ( JIoEndpoint . java : 489 )
at java . lang . Thread . run ( Unknown Source )
dreampeppers99 24 de jul. de 2011
Seguinte já tive esse problema uma vez por conta desse código aqui.
this.oClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
Uma vez foi por motivo de import errado e outra foi a jvm instalada mesmo (se me recordo bem).
Então faça o seguinte crie um teste e faça esse código ai em cima funcionar. (não precisa ser com as classes reais crie umas bobas e herde e veja… se tá correto)
@Test
public void deveriaCriarClasseX(){
ClasseX objecto = new ClasseX();
asserEquals(objecto.getClasse(),ClassX.class);
}
EuclidesFilizola 24 de jul. de 2011
Essa parte do arguments e talz… já está funcionando… agora volto para o ponto zero do problema. o entity continua null… e ele não faz a validação que eu criei… como teste
dreampeppers99 24 de jul. de 2011
E quando debuga ou dá um print em verificarExistenciaConta, não dá pra ver o que está nulo, se entity manager ou outra coisa?
Caused by: java.lang.NullPointerException
at br.com.fic.bancoFic.dao.ContaDAOImp.verificarExistenciaConta(ContaDAOImp.java:22)
at br.com.fic.bancoFic.negocio.ContaNegocio.verificarConta(ContaNegocio.java:19)
EuclidesFilizola 24 de jul. de 2011
no debbug, o entityManager vem NULL.
dreampeppers99 24 de jul. de 2011
então ele não está injetando o EntityManager pela anotação… :\
Tente mover o @PersistenceContext do atributo para o método
@PersistenceContext
public void setPersistenceContext(EntityManager em){
this.em = em;
}
EuclidesFilizola 24 de jul. de 2011
Fiz assim e não funcionou:
@PersistenceContext
public void setEntityManager ( EntityManager em ) {
this . entityManager = em ;
}
EuclidesFilizola 24 de jul. de 2011
Está dando erro quando eu executo o método dessa classe aqui
package br.com.fic.bancoFic.dao ;
import javax.persistence.Query ;
import org.springframework.stereotype.Repository ;
import org.springframework.transaction.annotation.Propagation ;
import org.springframework.transaction.annotation.Transactional ;
import br.com.fic.bancoFic.entidades.ContaBancaria ;
@Repository
@Transactional ( readOnly = true , propagation = Propagation . REQUIRED )
public class ContaDAOImp extends DAOGenericoImpl & lt ; ContaBancaria , Integer & gt ; implements ContaDAO {
@Transactional ( readOnly = true )
public boolean verificarExistenciaConta ( String agencia , String conta ){
boolean existeConta = false ;
ContaBancaria contaBancaria = new ContaBancaria ();
Query query = getEntityManager (). createNamedQuery ( "procurarConta" );
query . setParameter ( 1 , agencia );
query . setParameter ( 2 , conta );
contaBancaria = ( ContaBancaria ) query . getSingleResult ();
if ( contaBancaria != null )
existeConta = true ;
return existeConta ;
}
}
Na linha:
Query query = getEntityManager().createNamedQuery("procurarConta");
o getEntityManager vem NULL.
dreampeppers99 24 de jul. de 2011
);
conclusão que não ajuda muito mas sabemos que o Spring não está conseguindo injetar esse EM…
ahh cool, lembrei de uma coisa, como está utilizando a injeção desde o ManagedBean até o Dao?
EuclidesFilizola 24 de jul. de 2011
e ae… alguem pra me ajudar ?
EuclidesFilizola 24 de jul. de 2011
O mb faz a verificação por esse método:
public void verificarConta (){
contaNegocio = new ContaNegocio ();
contaNegocio . verificarConta ( this . getNumAgencia (), this . getNumConta ());
}
O contaNegocio verifica dessa forma
public boolean verificarConta ( String agencia , String conta ) {
verificaConta = contaDao .verificarExistenciaConta ( agencia , conta ) ;
return verificaConta ;
}
e o contaDao verifica desse jeito
public boolean verificarExistenciaConta ( String agencia , String conta ) {
boolean existeConta = false ;
ContaBancaria contaBancaria = new ContaBancaria () ;
Query query = getEntityManager () .createNamedQuery ( "procurarConta" ) ;
query .setParameter ( 1 , agencia ) ;
query .setParameter ( 2 , conta ) ;
contaBancaria = ( ContaBancaria ) query .getSingleResult () ;
if ( contaBancaria != null )
existeConta = true ;
return existeConta ;
}
dreampeppers99 24 de jul. de 2011
e a injeção do dao como é feita?
EuclidesFilizola 24 de jul. de 2011
Pois é. O dao não está configurado no applicationContext.
eu apenas estou herdando e implementando um no outro.
dessa forma
ContaDAO
package br . com . fic . bancoFic . dao ;
import org.springframework.stereotype.Repository ;
import org.springframework.transaction.annotation.Transactional ;
import br.com.fic.bancoFic.entidades.ContaBancaria ;
@Repository
@Transactional
public interface ContaDAO extends DAOGenerico & lt ; ContaBancaria , Integer & gt ; {
}
ContaDaoImpl
@ Repository
@ Transactional ( readOnly = true , propagation = Propagation . REQUIRED )
public class ContaDAOImp extends DAOGenericoImpl & lt ; ContaBancaria , Integer & gt ; implements ContaDAO {
e por ultimo o applicationcontext
& lt ;? xml version = "1.0" encoding = "UTF-8" ? & gt ;
& lt ; beans xmlns = "http://www.springframework.org/schema/beans"
xmlns : context = "http://www.springframework.org/schema/context"
xmlns : xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns : cxf = "http://cxf.apache.org/core"
xmlns : jaxws = "http://cxf.apache.org/jaxws" xmlns : tx = "http://www.springframework.org/schema/tx"
xmlns : p = "http://www.springframework.org/schema/p" xmlns : jaxrs = "http://cxf.apache.org/jaxrs"
xsi : schemaLocation = "
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd" & gt ;
& lt ; tx : annotation - driven /& gt ;
& lt ; tx : annotation - driven transaction - manager = "transactionManager" /& gt ;
& lt ; context : component - scan base - package = "br.com.fic.bancoFic" /& gt ;
& lt ; context : annotation - config /& gt ;
& lt ; bean id = "entityManagerFactory"
class = "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" & gt ;
& lt ; property name = "persistenceUnitName" value = "conexao" /& gt ;
& lt ; / bean & gt ;
& lt ; bean id = "transactionManager" class = "org.springframework.orm.jpa.JpaTransactionManager" & gt ;
& lt ; property name = "entityManagerFactory" ref = "entityManagerFactory" /& gt ;
& lt ; / bean & gt ;
& lt ; / beans & gt ;
dreampeppers99 24 de jul. de 2011
Digo, como está criando o managedbean e do managedbean como está instanciando esse dao?
EuclidesFilizola 24 de jul. de 2011
Estou instanciando pelo contaNegocio.
public class ContaNegocio {
ContaDAOImp contaDao = new ContaDAOImp ();
boolean verificaConta = false ;
public boolean verificarConta ( String agencia , String conta ){
verificaConta = contaDao . verificarExistenciaConta ( agencia , conta );
return verificaConta ;
}
public List & lt ; ContaBancaria & gt ; getListaTodosContas () throws Exception {
return ( List & lt ; ContaBancaria & gt ;) this . contaDao . todos ();
}
public void salvarConta ( ContaBancaria ent ) throws Exception {
if ( ent . getId () == 0 ) {
}
this . contaDao . salvar ( ent );
}
public void deletarConta ( ContaBancaria ent ) throws Exception {
this . contaDao . excluir ( ent );
}
}
dreampeppers99 24 de jul. de 2011
Tá aí o erro amigo.
Você deve pedir o Spring esse bean gerenciado pelo Spring daí ele vai te dar ele com todas as características (tx, injeção do em).
Resource res = new FileSystemResource("c:\caminhocompleto\beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(res);
contaDao = (ContaDAO )factory.getBean("contaDAO");
O correto seria integrar o spring para gerar os managedbean e dai pra frente gerenciar tudo…
EuclidesFilizola 24 de jul. de 2011
É pq eu peguei o exemplo do livro do edson gonçalves, e ele faz exatamente oq eu estava tentando fazer.
bom, então como eu devo configurar para que o spring gere os mbeans ?
dreampeppers99 24 de jul. de 2011
Na documentação oficial tem como integrar spring com jsf mas é mais ou menos assim, não seu teu conhecimento em JSF portanto se eu estiver falando coisas que você já sabe só ignore.
Você configura o Spring para ser seu resolvedor de expressões (EL aquelas expressões (EL #) que ficam nas tags <h:input value="#{mb.campo}">, por exemplo quando o jsf for criar o bean mb ele vai delegar esse trabalho ao Spring que vai procurar (no seu caso que está configurado pra procurar componentes anotados) um bean (@Component ou mais especificamente @Controller ) que bate com o nome mb (nas anotações @Repository @Controller você pode nomear) e achando ele vai criar toda a estrutuda de dependencia (conforme configurado no appctx.xml ) seja por anotação @Inject ou seja por definições no xml.
EuclidesFilizola 24 de jul. de 2011
Beleza cara, eu vou dar uma olhada em tudo q vc falou ae… obrigado pela ajuda… vou me esforçar aqui pra obter algum resultado positivo. qualquer coisa eu posto por aqui… Obrigado…
Abraços.
raf4ever 25 de jul. de 2011
Euclides,deixa eu te mostrar como faço essa integração,aki comigo funciona blz:
applicationContext.xml:
& lt ;? xml version = "1.0" encoding = "UTF-8" ? & gt ;
& lt ; beans xmlns = "http://www.springframework.org/schema/beans"
xmlns : xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns : context = "http://www.springframework.org/schema/context"
xmlns : tx = "http://www.springframework.org/schema/tx"
xsi : schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" & gt ;
& lt ; bean id = "entityManagerFactory"
class = "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" & gt ;
& lt ; property name = "persistenceUnitName" value = "myPU" /& gt ;
& lt ; / bean & gt ;
& lt ; bean id = "myDataSource" class = "org.apache.commons.dbcp.BasicDataSource"
destroy - method = "close" & gt ;
& lt ; property name = "driverClassName" value = "org.postgresql.Driver" /& gt ;
& lt ; property name = "url" value = "jdbc:postgresql://localhost:5432/xxxxxxx" /& gt ;
& lt ; property name = "username" value = "postgres" /& gt ;
& lt ; property name = "password" value = "postgres" /& gt ;
& lt ; / bean & gt ;
& lt ; bean
class = "org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" /& gt ;
& lt ; bean
class = "org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /& gt ;
& lt ; bean id = "transactionManager" class = "org.springframework.orm.jpa.JpaTransactionManager" & gt ;
& lt ; property name = "entityManagerFactory" ref = "entityManagerFactory" /& gt ;
& lt ; / bean & gt ;
& lt ; bean id = "contextApplicationContextProvider" class = "context.ApplicationContextProvider" /& gt ;
& lt ; tx : annotation - driven /& gt ;
& lt ; context : component - scan base - package = "*" /& gt ;
& lt ; / beans & gt ;
Implementação de DAO:
@ Component
public class ClienteDAOImp extends GenericDAOImp & lt ; Cliente , Long & gt ;
implements ClienteDAO {
@ Override
@ Transactional
public List & lt ; Cliente & gt ; findByExample ( Cliente filtro ) {
Criteria c = criaCriteria ();
if ( filtro . getNome () != null && ! ( filtro . getNome () . isEmpty ())){
c . add ( Restrictions . ilike ( "nome" , filtro . getNome (), MatchMode . ANYWHERE ));
}
c . addOrder ( Order . asc ( "nome" ));
return ( List & lt ; Cliente & gt ;) c . list ();
}
}
Injeção do DAO no MB:
@Component
@Scope ( "globalSession" )
public class ClienteController {
@Resource
ClienteDAO dao ;
EuclidesFilizola 26 de jul. de 2011
Bom dia pessoal,
depois de algumas modificações que eu fiz, aparece o seguinte erro:
SEVERE : org . springframework . transaction . CannotCreateTransactionException : Could not open JPA EntityManager for transaction ; nested exception is java . lang . UnsupportedOperationException : The user must supply a JDBC connection
javax . faces . el . EvaluationException : org . springframework . transaction . CannotCreateTransactionException : Could not open JPA EntityManager for transaction ; nested exception is java . lang . UnsupportedOperationException : The user must supply a JDBC connection
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 102 )
at com . sun . faces . application . ActionListenerImpl . processAction ( ActionListenerImpl . java : 102 )
at javax . faces . component . UICommand . broadcast ( UICommand . java : 387 )
at org . ajax4jsf . component . AjaxViewRoot . processEvents ( AjaxViewRoot . java : 321 )
at org . ajax4jsf . component . AjaxViewRoot . broadcastEvents ( AjaxViewRoot . java : 296 )
at org . ajax4jsf . component . AjaxViewRoot . processPhase ( AjaxViewRoot . java : 253 )
at org . ajax4jsf . component . AjaxViewRoot . processApplication ( AjaxViewRoot . java : 466 )
at com . sun . faces . lifecycle . InvokeApplicationPhase . execute ( InvokeApplicationPhase . java : 82 )
at com . sun . faces . lifecycle . Phase . doPhase ( Phase . java : 100 )
at com . sun . faces . lifecycle . LifecycleImpl . execute ( LifecycleImpl . java : 118 )
at javax . faces . webapp . FacesServlet . service ( FacesServlet . java : 265 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . springframework . orm . jpa . support . OpenEntityManagerInViewFilter . doFilterInternal ( OpenEntityManagerInViewFilter . java : 112 )
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 . ajax4jsf . webapp . BaseXMLFilter . doXmlFilter ( BaseXMLFilter . java : 178 )
at org . ajax4jsf . webapp . BaseFilter . handleRequest ( BaseFilter . java : 290 )
at org . ajax4jsf . webapp . BaseFilter . processUploadsAndHandleRequest ( BaseFilter . java : 390 )
at org . ajax4jsf . webapp . BaseFilter . doFilter ( BaseFilter . java : 517 )
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 : 233 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 191 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 127 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 102 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 109 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 298 )
at org . apache . coyote . http11 . Http11Processor . process ( Http11Processor . java : 859 )
at org . apache . coyote . http11 . Http11Protocol$Http11ConnectionHandler . process ( Http11Protocol . java : 588 )
at org . apache . tomcat . util . net . JIoEndpoint$Worker . run ( JIoEndpoint . java : 489 )
at java . lang . Thread . run ( Unknown Source )
Caused by : org . springframework . transaction . CannotCreateTransactionException : Could not open JPA EntityManager for transaction ; nested exception is java . lang . UnsupportedOperationException : The user must supply a JDBC connection
at org . springframework . orm . jpa . JpaTransactionManager . doBegin ( JpaTransactionManager . java : 375 )
at org . springframework . transaction . support . AbstractPlatformTransactionManager . getTransaction ( AbstractPlatformTransactionManager . java : 377 )
at org . springframework . transaction . interceptor . TransactionAspectSupport . createTransactionIfNecessary ( TransactionAspectSupport . java : 263 )
at org . springframework . transaction . interceptor . TransactionInterceptor . invoke ( TransactionInterceptor . java : 101 )
at org . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 171 )
at org . springframework . aop . framework . JdkDynamicAopProxy . invoke ( JdkDynamicAopProxy . java : 204 )
at $Proxy18 . verificarExistenciaConta ( Unknown Source )
at br . com . fic . bancoFic . mBeans . ContaBancariaBean . verificarConta ( ContaBancariaBean . java : 32 )
at sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
at sun . reflect . NativeMethodAccessorImpl . invoke ( Unknown Source )
at sun . reflect . DelegatingMethodAccessorImpl . invoke ( Unknown Source )
at java . lang . reflect . Method . invoke ( Unknown Source )
at org . apache . el . parser . AstValue . invoke ( AstValue . java : 191 )
at org . apache . el . MethodExpressionImpl . invoke ( MethodExpressionImpl . java : 276 )
at com . sun . facelets . el . TagMethodExpression . invoke ( TagMethodExpression . java : 68 )
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 88 )
... 32 more
Caused by : java . lang . UnsupportedOperationException : The user must supply a JDBC connection
at org . hibernate . connection . UserSuppliedConnectionProvider . getConnection ( UserSuppliedConnectionProvider . java : 54 )
at org . hibernate . jdbc . ConnectionManager . openConnection ( ConnectionManager . java : 446 )
at org . hibernate . jdbc . ConnectionManager . getConnection ( ConnectionManager . java : 167 )
at org . hibernate . jdbc . JDBCContext . connection ( JDBCContext . java : 142 )
at org . hibernate . transaction . JDBCTransaction . begin ( JDBCTransaction . java : 85 )
at org . hibernate . impl . SessionImpl . beginTransaction ( SessionImpl . java : 1353 )
at org . hibernate . ejb . TransactionImpl . begin ( TransactionImpl . java : 38 )
at org . springframework . orm . jpa . DefaultJpaDialect . beginTransaction ( DefaultJpaDialect . java : 70 )
at org . springframework . orm . jpa . JpaTransactionManager . doBegin ( JpaTransactionManager . java : 330 )
... 47 more
26 / Jul / 2011 11 : 04 : 37 com . sun . faces . lifecycle . InvokeApplicationPhase execute
WARNING : # { contaBancariaBean . verificarConta } : org . springframework . transaction . CannotCreateTransactionException : Could not open JPA EntityManager for transaction ; nested exception is java . lang . UnsupportedOperationException : The user must supply a JDBC connection
javax . faces . FacesException : # { contaBancariaBean . verificarConta } : org . springframework . transaction . CannotCreateTransactionException : Could not open JPA EntityManager for transaction ; nested exception is java . lang . UnsupportedOperationException : The user must supply a JDBC connection
at com . sun . faces . application . ActionListenerImpl . processAction ( ActionListenerImpl . java : 118 )
at javax . faces . component . UICommand . broadcast ( UICommand . java : 387 )
at org . ajax4jsf . component . AjaxViewRoot . processEvents ( AjaxViewRoot . java : 321 )
at org . ajax4jsf . component . AjaxViewRoot . broadcastEvents ( AjaxViewRoot . java : 296 )
at org . ajax4jsf . component . AjaxViewRoot . processPhase ( AjaxViewRoot . java : 253 )
at org . ajax4jsf . component . AjaxViewRoot . processApplication ( AjaxViewRoot . java : 466 )
at com . sun . faces . lifecycle . InvokeApplicationPhase . execute ( InvokeApplicationPhase . java : 82 )
at com . sun . faces . lifecycle . Phase . doPhase ( Phase . java : 100 )
at com . sun . faces . lifecycle . LifecycleImpl . execute ( LifecycleImpl . java : 118 )
at javax . faces . webapp . FacesServlet . service ( FacesServlet . java : 265 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . springframework . orm . jpa . support . OpenEntityManagerInViewFilter . doFilterInternal ( OpenEntityManagerInViewFilter . java : 112 )
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 . ajax4jsf . webapp . BaseXMLFilter . doXmlFilter ( BaseXMLFilter . java : 178 )
at org . ajax4jsf . webapp . BaseFilter . handleRequest ( BaseFilter . java : 290 )
at org . ajax4jsf . webapp . BaseFilter . processUploadsAndHandleRequest ( BaseFilter . java : 390 )
at org . ajax4jsf . webapp . BaseFilter . doFilter ( BaseFilter . java : 517 )
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 : 233 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 191 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 127 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 102 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 109 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 298 )
at org . apache . coyote . http11 . Http11Processor . process ( Http11Processor . java : 859 )
at org . apache . coyote . http11 . Http11Protocol$Http11ConnectionHandler . process ( Http11Protocol . java : 588 )
at org . apache . tomcat . util . net . JIoEndpoint$Worker . run ( JIoEndpoint . java : 489 )
at java . lang . Thread . run ( Unknown Source )
Caused by : javax . faces . el . EvaluationException : org . springframework . transaction . CannotCreateTransactionException : Could not open JPA EntityManager for transaction ; nested exception is java . lang . UnsupportedOperationException : The user must supply a JDBC connection
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 102 )
at com . sun . faces . application . ActionListenerImpl . processAction ( ActionListenerImpl . java : 102 )
... 31 more
Caused by : org . springframework . transaction . CannotCreateTransactionException : Could not open JPA EntityManager for transaction ; nested exception is java . lang . UnsupportedOperationException : The user must supply a JDBC connection
at org . springframework . orm . jpa . JpaTransactionManager . doBegin ( JpaTransactionManager . java : 375 )
at org . springframework . transaction . support . AbstractPlatformTransactionManager . getTransaction ( AbstractPlatformTransactionManager . java : 377 )
at org . springframework . transaction . interceptor . TransactionAspectSupport . createTransactionIfNecessary ( TransactionAspectSupport . java : 263 )
at org . springframework . transaction . interceptor . TransactionInterceptor . invoke ( TransactionInterceptor . java : 101 )
at org . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 171 )
at org . springframework . aop . framework . JdkDynamicAopProxy . invoke ( JdkDynamicAopProxy . java : 204 )
at $Proxy18 . verificarExistenciaConta ( Unknown Source )
at br . com . fic . bancoFic . mBeans . ContaBancariaBean . verificarConta ( ContaBancariaBean . java : 32 )
at sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
at sun . reflect . NativeMethodAccessorImpl . invoke ( Unknown Source )
at sun . reflect . DelegatingMethodAccessorImpl . invoke ( Unknown Source )
at java . lang . reflect . Method . invoke ( Unknown Source )
at org . apache . el . parser . AstValue . invoke ( AstValue . java : 191 )
at org . apache . el . MethodExpressionImpl . invoke ( MethodExpressionImpl . java : 276 )
at com . sun . facelets . el . TagMethodExpression . invoke ( TagMethodExpression . java : 68 )
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 88 )
... 32 more
Caused by : java . lang . UnsupportedOperationException : The user must supply a JDBC connection
at org . hibernate . connection . UserSuppliedConnectionProvider . getConnection ( UserSuppliedConnectionProvider . java : 54 )
at org . hibernate . jdbc . ConnectionManager . openConnection ( ConnectionManager . java : 446 )
at org . hibernate . jdbc . ConnectionManager . getConnection ( ConnectionManager . java : 167 )
at org . hibernate . jdbc . JDBCContext . connection ( JDBCContext . java : 142 )
at org . hibernate . transaction . JDBCTransaction . begin ( JDBCTransaction . java : 85 )
at org . hibernate . impl . SessionImpl . beginTransaction ( SessionImpl . java : 1353 )
at org . hibernate . ejb . TransactionImpl . begin ( TransactionImpl . java : 38 )
at org . springframework . orm . jpa . DefaultJpaDialect . beginTransaction ( DefaultJpaDialect . java : 70 )
at org . springframework . orm . jpa . JpaTransactionManager . doBegin ( JpaTransactionManager . java : 330 )
... 47 more
26 / Jul / 2011 11 : 04 : 37 com . sun . faces . lifecycle . Phase doPhase
SEVERE : JSF1054 : ( Phase ID : INVOKE_APPLICATION 5 , View ID : / login . xhtml ) Exception thrown during phase execution : javax . faces . event . PhaseEvent [ source = com . sun . faces . lifecycle . LifecycleImpl @1 b0d235 ]
26 / Jul / 2011 11 : 04 : 37 org . apache . catalina . core . StandardWrapperValve invoke
SEVERE : Servlet . service () for servlet Faces Servlet threw exception
java . lang . UnsupportedOperationException : The user must supply a JDBC connection
at org . hibernate . connection . UserSuppliedConnectionProvider . getConnection ( UserSuppliedConnectionProvider . java : 54 )
at org . hibernate . jdbc . ConnectionManager . openConnection ( ConnectionManager . java : 446 )
at org . hibernate . jdbc . ConnectionManager . getConnection ( ConnectionManager . java : 167 )
at org . hibernate . jdbc . JDBCContext . connection ( JDBCContext . java : 142 )
at org . hibernate . transaction . JDBCTransaction . begin ( JDBCTransaction . java : 85 )
at org . hibernate . impl . SessionImpl . beginTransaction ( SessionImpl . java : 1353 )
at org . hibernate . ejb . TransactionImpl . begin ( TransactionImpl . java : 38 )
at org . springframework . orm . jpa . DefaultJpaDialect . beginTransaction ( DefaultJpaDialect . java : 70 )
at org . springframework . orm . jpa . JpaTransactionManager . doBegin ( JpaTransactionManager . java : 330 )
at org . springframework . transaction . support . AbstractPlatformTransactionManager . getTransaction ( AbstractPlatformTransactionManager . java : 377 )
at org . springframework . transaction . interceptor . TransactionAspectSupport . createTransactionIfNecessary ( TransactionAspectSupport . java : 263 )
at org . springframework . transaction . interceptor . TransactionInterceptor . invoke ( TransactionInterceptor . java : 101 )
at org . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 171 )
at org . springframework . aop . framework . JdkDynamicAopProxy . invoke ( JdkDynamicAopProxy . java : 204 )
at $Proxy18 . verificarExistenciaConta ( Unknown Source )
at br . com . fic . bancoFic . mBeans . ContaBancariaBean . verificarConta ( ContaBancariaBean . java : 32 )
at sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
at sun . reflect . NativeMethodAccessorImpl . invoke ( Unknown Source )
at sun . reflect . DelegatingMethodAccessorImpl . invoke ( Unknown Source )
at java . lang . reflect . Method . invoke ( Unknown Source )
at org . apache . el . parser . AstValue . invoke ( AstValue . java : 191 )
at org . apache . el . MethodExpressionImpl . invoke ( MethodExpressionImpl . java : 276 )
at com . sun . facelets . el . TagMethodExpression . invoke ( TagMethodExpression . java : 68 )
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 88 )
at com . sun . faces . application . ActionListenerImpl . processAction ( ActionListenerImpl . java : 102 )
at javax . faces . component . UICommand . broadcast ( UICommand . java : 387 )
at org . ajax4jsf . component . AjaxViewRoot . processEvents ( AjaxViewRoot . java : 321 )
at org . ajax4jsf . component . AjaxViewRoot . broadcastEvents ( AjaxViewRoot . java : 296 )
at org . ajax4jsf . component . AjaxViewRoot . processPhase ( AjaxViewRoot . java : 253 )
at org . ajax4jsf . component . AjaxViewRoot . processApplication ( AjaxViewRoot . java : 466 )
at com . sun . faces . lifecycle . InvokeApplicationPhase . execute ( InvokeApplicationPhase . java : 82 )
at com . sun . faces . lifecycle . Phase . doPhase ( Phase . java : 100 )
at com . sun . faces . lifecycle . LifecycleImpl . execute ( LifecycleImpl . java : 118 )
at javax . faces . webapp . FacesServlet . service ( FacesServlet . java : 265 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . springframework . orm . jpa . support . OpenEntityManagerInViewFilter . doFilterInternal ( OpenEntityManagerInViewFilter . java : 112 )
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 . ajax4jsf . webapp . BaseXMLFilter . doXmlFilter ( BaseXMLFilter . java : 178 )
at org . ajax4jsf . webapp . BaseFilter . handleRequest ( BaseFilter . java : 290 )
at org . ajax4jsf . webapp . BaseFilter . processUploadsAndHandleRequest ( BaseFilter . java : 390 )
at org . ajax4jsf . webapp . BaseFilter . doFilter ( BaseFilter . java : 517 )
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 : 233 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 191 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 127 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 102 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 109 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 298 )
at org . apache . coyote . http11 . Http11Processor . process ( Http11Processor . java : 859 )
at org . apache . coyote . http11 . Http11Protocol$Http11ConnectionHandler . process ( Http11Protocol . java : 588 )
at org . apache . tomcat . util . net . JIoEndpoint$Worker . run ( JIoEndpoint . java : 489 )
at java . lang . Thread . run ( Unknown Source )
aqui está meu applicationcontex
& lt ;? xml version = "1.0" encoding = "UTF-8" ? & gt ;
& lt ; beans xmlns = "http://www.springframework.org/schema/beans"
xmlns : context = "http://www.springframework.org/schema/context"
xmlns : xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns : cxf = "http://cxf.apache.org/core"
xmlns : jaxws = "http://cxf.apache.org/jaxws" xmlns : tx = "http://www.springframework.org/schema/tx"
xmlns : p = "http://www.springframework.org/schema/p" xmlns : jaxrs = "http://cxf.apache.org/jaxrs"
xsi : schemaLocation = "
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd" & gt ;
& lt ; tx : annotation - driven /& gt ;
& lt ; context : annotation - config /& gt ;
& lt ; context : component - scan base - package = "*" /& gt ;
& lt ; bean id = "entityManagerFactory" class = "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" & gt ;
& lt ; property name = "persistenceUnitName" value = "conexao" /& gt ;
& lt ; / bean & gt ;
& lt ; bean id = "transactionManager" class = "org.springframework.orm.jpa.JpaTransactionManager" & gt ;
& lt ; property name = "entityManagerFactory" ref = "entityManagerFactory" /& gt ;
& lt ; / bean & gt ;
& lt ; / beans & gt ;
e aqui está o persistence.xml
& lt ;? xml version = "1.0" encoding = "UTF-8" ?& gt ;
& lt ; persistence version = "1.0"
xmlns = "http://java.sun.com/xml/ns/persistence" xmlns : xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi : schemaLocation = "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" & gt ;
& lt ; persistence-unit name = "conexao" & gt ;
& lt ; provider & gt ; org . hibernate . ejb . HibernatePersistence & lt ;/ provider & gt ;
& lt ; class & gt ; br . com . fic . bancoFic . entidades . ContaBancaria & lt ;/ class & gt ;
& lt ; class & gt ; br . com . fic . bancoFic . entidades . Entidade & lt ;/ class & gt ;
& lt ; class & gt ; br . com . fic . bancoFic . entidades . Movimentacao & lt ;/ class & gt ;
& lt ; class & gt ; br . com . fic . bancoFic . entidades . Pagamento & lt ;/ class & gt ;
& lt ; properties & gt ;
& lt ; property name = "hibernate.dialect" value = "org.hibernatespatial.mysql.MySQLSpatialDialect" /& gt ;
& lt ; property name = "hibernate.cache.provider_class" value = "net.sf.ehcache.hibernate.EhCacheProvider" /& gt ;
& lt ; property name = "hibernate.cache.use_second_level_cache" value = "true" /& gt ;
& lt ; property name = "hibernate.cache.use_query_cache" value = "true" /& gt ;
& lt ; property name = "hibernate.format_sql" value = "false" /& gt ;
& lt ; property name = "hibernate.show_sql" value = "false" /& gt ;
& lt ;! --property name = "hibernate.hbm2ddl.auto" value = "update" / -- & gt ;
& lt ; property name = "hibernate.query.substitutions" value = "true 1, false 0" /& gt ;
& lt ; property name = "hibernate.max_fetch_depth" value = "0" /& gt ; & lt ;/ properties & gt ;
& lt ;/ persistence-unit & gt ;
& lt ;/ persistence & gt ;
…Alguém saberia me dizer ?
raf4ever 26 de jul. de 2011
Tá faltando coisa nesse teu apllicationContext ae
Se baseia nesse exemplo que eu passei que dá certo.