GUJ Discussões   :   últimos tópicos   |   categorias   |   GUJ Respostas

Erro no controler de um projeto em JSF

java
jsf
Tags: #<Tag:0x00007f241c34b9c0> #<Tag:0x00007f241c34b718>

#21

Uma coisa que você precisa fazer, com urgência, é aprender a ler o erro.
Qual o código contido na linha indicada PaisDao.java:27?


#22

Entendi que o erro está aqui e que está nulo.

Mas ao fazer o debug, ai fiquei confuso.


#23

O objeto em, do EntityManager está nulo.
Entenda uma coisa: você só terá um NullPointerException caso tente acessar um atributo ou invocar um método de um objeto nulo.
O objeto query está instanciado e esta instância se refere a “SELECT p FROM PaisEntity p”. Mas, independente disso, você não invoca nenhum método nele.
Teu projeto é web? O que está usando nele? Que tecnologias?


#24

Isto eu entendi.

Eu não estou conseguindo é instanciar este objeto no jsf.

Em um projeto no Spring, com o mesmo banco de dados, funcionou e com jsf não.

É um projeto web.

Estou utilizando maven, hibernate, jpa,jsf, primefaces, postgres.

No Spring, ele instancia só de ter isto

@PersistenceContext
EntityManager em;

Neste do JSF não, realmente está nulo.


#25

Está rodando este projeto onde? Tomcat? Glassfish? Wildfly?


#26

Tomcat 8.


#27

Como está teu pom.xml?
O tomcat não é um application server, logo, ele não possui a estrutura necessária para que o JPA funcione corretamente. Isso vai depender do que você tem em teu projeto.


#28

Correto.

Eu queria configurar o jboss, mas também é outro passo.

Meu pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>br.com.netsoft</groupId>
	<artifactId>desif</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>desif</name>
	<description>desif</description>

	<properties>
		<java-version>1.8</java-version>
		<org.springframework-version>4.1.0.RELEASE</org.springframework-version>
		<org.aspectj-version>1.8.1</org.aspectj-version>
		<org.slf4j-version>1.6.6</org.slf4j-version>
	</properties>

	<dependencies>

		<!-- JSF -->
		<dependency>
			<groupId>com.sun.faces</groupId>
			<artifactId>jsf-api</artifactId>
			<version>2.2.13</version>
		</dependency>

		<!-- JSF -->
		<dependency>
			<groupId>com.sun.faces</groupId>
			<artifactId>jsf-impl</artifactId>
			<version>2.2.13</version>
		</dependency>

		<dependency>
			<groupId>javax.validation</groupId>
			<artifactId>validation-api</artifactId>
			<version>1.0.0.GA</version>
		</dependency>

		<!-- PrimeFaces -->
		<dependency>
			<groupId>org.primefaces</groupId>
			<artifactId>primefaces</artifactId>
			<version>5.3</version>
		</dependency>

		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.2.2</version>
		</dependency>

		<!-- AspectJ -->
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjrt</artifactId>
			<version>${org.aspectj-version}</version>
		</dependency>

		<!-- Logging -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>${org.slf4j-version}</version>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jcl-over-slf4j</artifactId>
			<version>${org.slf4j-version}</version>
			<scope>runtime</scope>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>${org.slf4j-version}</version>
			<scope>runtime</scope>
		</dependency>

		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.15</version>
			<exclusions>

				<exclusion>
					<groupId>javax.mail</groupId>
					<artifactId>mail</artifactId>
				</exclusion>

				<exclusion>
					<groupId>javax.jms</groupId>
					<artifactId>jms</artifactId>
				</exclusion>

				<exclusion>
					<groupId>com.sun.jdmk</groupId>
					<artifactId>jmxtools</artifactId>
				</exclusion>

				<exclusion>
					<groupId>com.sun.jmx</groupId>
					<artifactId>jmxri</artifactId>
				</exclusion>

			</exclusions>
			<scope>runtime</scope>
		</dependency>

		<!-- @Inject -->
		<dependency>
			<groupId>javax.inject</groupId>
			<artifactId>javax.inject</artifactId>
			<version>1</version>
		</dependency>

		<!-- CDI -->
		<dependency>
			<groupId>javax.enterprise</groupId>
			<artifactId>cdi-api</artifactId>
			<version>1.2</version>
			<scope>provided</scope>
		</dependency>

		<!--JBoss/Weld implementação de referência do CDI para Servlet Container(Exemplo:Tomcat) -->
		<dependency>
			<groupId>org.jboss.weld.servlet</groupId>
			<artifactId>weld-servlet</artifactId>
			<version>2.2.6.Final</version>
			<scope>runtime</scope>
		</dependency>

		<!-- Métodos uteis para manipulação de String, métodos e etc -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
			<version>3.4</version>
		</dependency>

		<!-- PROVIDER JPA(HIBERNATE) -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-entitymanager</artifactId>
			<version>4.3.0.Final</version>
		</dependency>

		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-validator</artifactId>
			<version>4.1.0.Final</version>
		</dependency>

		<dependency>
			<groupId>org.hibernate.javax.persistence</groupId>
			<artifactId>hibernate-jpa-2.0-api</artifactId>
			<version>1.0.0.Final</version>
		</dependency>

		<!-- Servlet -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.1</version>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>

		<!-- DEPENDENCIA Postgres -->
		<dependency>
			<groupId>postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<version>9.1-901.jdbc4</version>
		</dependency>

		<!-- usado pelo Weld -->
		<dependency>
			<groupId>org.jboss</groupId>
			<artifactId>jandex</artifactId>
			<version>1.2.2.Final</version>
		</dependency>

		<!-- Manipulação de XML -->
		<dependency>
			<groupId>jdom</groupId>
			<artifactId>jdom</artifactId>
			<version>1.1</version>
		</dependency>

		<!-- Test -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.7</version>
			<scope>test</scope>
		</dependency>

		<!-- Codehaus Jackson -->

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.5.1</version>
		</dependency>

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
			<version>2.5.1</version>
		</dependency>

	</dependencies>

	<build>
		<finalName>desif</finalName>
		<plugins>

			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>exec-maven-plugin</artifactId>
				<version>1.2.1</version>
				<configuration>
					<mainClass>org.test.int1.Main</mainClass>
				</configuration>
			</plugin>

			<plugin>
				<artifactId>maven-eclipse-plugin</artifactId>
				<version>2.9</version>
				<configuration>
					<additionalProjectnatures>
						<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
					</additionalProjectnatures>
					<additionalBuildcommands>
						<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
					</additionalBuildcommands>
					<downloadSources>true</downloadSources>
					<downloadJavadocs>true</downloadJavadocs>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.5.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

#29

Mais algo que posso fazer ?


#30

Fiz estas alterações e mudou o erro.

Acho que a classe não está persistindo, conforme descrição do log:

Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named PaisEntity
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at br.com.netsoft.desif.dao.endereco.PaisDao.listarPaises(PaisDao.java:28)
at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:43)
… 54 more

DAO

public class PaisDao implements Serializable {

	private static final long serialVersionUID = 1402488530698938353L;

	final private String hql = " p FROM PaisEntity p ";

	EntityManager em;

	public List<PaisEntity> listarPaises() {
		
		StringBuilder hqlSelect = new StringBuilder(hql);

		final String query = "SELECT" + hqlSelect;

		EntityManagerFactory factory = Persistence.createEntityManagerFactory("PaisEntity");
		
		EntityManager manager = factory.createEntityManager();
		
		Query querySelect = manager.createQuery(query);
		
		@SuppressWarnings("unchecked")
		List<PaisEntity> resultList = querySelect.getResultList();

		return resultList;

	}

}

LOGS

mar 21, 2017 8:31:59 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
GRAVE: Error Rendering View[/index.xhtml]
javax.el.ELException: /index.xhtml: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler
	at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:90)
	at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
	at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:227)
	at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
	at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
	at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
	at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
	at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
	at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
	at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
	... 33 more
Caused by: com.sun.faces.spi.InjectionProviderException
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:115)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
	... 47 more
Caused by: java.lang.reflect.InvocationTargetException
	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 com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
	... 49 more
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named PaisEntity
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
	at br.com.netsoft.desif.dao.endereco.PaisDao.listarPaises(PaisDao.java:28)
	at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:43)
	... 54 more

mar 21, 2017 8:31:59 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/desif] threw exception [Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler] with root cause
javax.persistence.PersistenceException: No Persistence provider for EntityManager named PaisEntity
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
	at br.com.netsoft.desif.dao.endereco.PaisDao.listarPaises(PaisDao.java:28)
	at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:43)
	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 com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
	at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
	at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
	at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
	at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
	at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
	at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
	at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
	at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
	at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)

mar 21, 2017 8:34:39 PM org.apache.catalina.core.StandardContext reload
INFORMAÇÕES: Reloading Context with name [/desif] has started
mar 21, 2017 8:34:39 PM org.apache.catalina.core.StandardContext listenerStop
GRAVE: Exception sending context destroyed event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.NoSuchMethodError: org.primefaces.context.ApplicationContext.getCurrentInstance()Lorg/primefaces/context/ApplicationContext;
	at org.primefaces.webapp.PreDestroyApplicationEventListener.processEvent(PreDestroyApplicationEventListener.java:30)
	at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
	at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2187)
	at com.sun.faces.application.ApplicationImpl.invokeListenersFor(ApplicationImpl.java:2163)
	at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:296)
	at org.jboss.weld.environment.servlet.jsf.ForwardingApplication.publishEvent(ForwardingApplication.java:282)
	at com.sun.faces.config.ConfigureListener.contextDestroyed(ConfigureListener.java:314)
	at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4799)
	at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5438)
	at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)
	at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3802)
	at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:292)
	at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5572)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1388)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1392)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1392)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1360)
	at java.lang.Thread.run(Unknown Source)

#31

Cara, quantas vezes terei que dizer que o problema está no EntityManager que não foi injetado?
Ontem você disse que tinha colocado a anotação no mesmo, mas o código que postou agora diz o contrário
`private static final long serialVersionUID = 1402488530698938353L;

final private String hql = " p FROM PaisEntity p ";

EntityManager em;`

Onde está a anotação?


#32

@Luis_Augusto_Santos, nesta mensagem eu informei que fiz e não adiantou.


#33

E só por que não adiantou você removeu?
Essa anotação deve ficar lá, nunca deve sair.


#34

Estava tentando de outra forma @Luis_Augusto_Santos.

Ou isto está errado ?

StringBuilder hqlSelect = new StringBuilder(hql);

final String query = "SELECT" + hqlSelect;

EntityManagerFactory factory = Persistence.createEntityManagerFactory("PaisEntity");
	
EntityManager manager = factory.createEntityManager();
	
Query querySelect = manager.createQuery(query);
	
@SuppressWarnings("unchecked")
List<PaisEntity> resultList = querySelect.getResultList();

return resultList;

#35

Vou voltar com a anotação


#36

Voltei ao DAO que estava antes:

package br.com.netsoft.desif.dao.endereco;

import java.io.Serializable;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import br.com.netsoft.desif.model.endereco.PaisEntity;

public class PaisDao implements Serializable {

	private static final long serialVersionUID = 1402488530698938353L;

	final private String hql = " p FROM PaisEntity p ";

	@PersistenceContext
	EntityManager em;

	public List<PaisEntity> listarPaises() {

		StringBuilder hqlSelect = new StringBuilder(hql);

		final String query = "SELECT " + hqlSelect;

		Query querySelect = em.createQuery(query);

		@SuppressWarnings("unchecked")
		List<PaisEntity> resultList = querySelect.getResultList();

		return resultList;

	}

}

O erro é:

mar 22, 2017 2:17:37 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
GRAVE: Error Rendering View[/index.xhtml]
javax.el.ELException: /index.xhtml: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:90)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:227)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
… 33 more
Caused by: com.sun.faces.spi.InjectionProviderException
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:115)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
… 47 more
Caused by: java.lang.reflect.InvocationTargetException
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 com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
… 49 more
Caused by: java.lang.NullPointerException
at br.com.netsoft.desif.dao.endereco.PaisDao.listarPaises(PaisDao.java:27)
at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:43)
… 54 more

mar 22, 2017 2:17:37 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/desif] threw exception [Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler] with root cause
java.lang.NullPointerException
at br.com.netsoft.desif.dao.endereco.PaisDao.listarPaises(PaisDao.java:27)
at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:43)
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 com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

Voltou ao erro de NullPointerException

Caused by: java.lang.NullPointerException
at br.com.netsoft.desif.dao.endereco.PaisDao.listarPaises(PaisDao.java:27)
at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:43)
… 54 more

Eu acho que o sistema não está persistindo as classes do persistence.xml


#37

Voce esta tentando injetar uma dependencia que é container-managed sem estar em um container, coloque a anotação @Stateless na sua classe

http://docs.oracle.com/javaee/7/api/javax/persistence/PersistenceContext.html


#38

@matrella2, para isso ele precisará incluir artefatos no pom.xml


#39

Achei que ele estava em um servidor de aplicação, parece que no controller ele não instanciou o paisDao, não sei se pretende utilizar injeção de dependencias, mas se for o caso e estiver usando o weld, teria que remover a anotação managed bean do JSF e utilizar a Named para o weld reconhecer alem de implementar o serializable.


#40

Na verdade, ele está utilizando tomcat 8 (logo, não é um application server).
Até rodaria EJB, mas teria que incluir as dependências.
Ele importou no pom.xml os artefatos para o CDI (por isso, talvez funcionasse a questão da injeção no controller.