JTA com SPRING + Hibernate + JPA

0 respostas
Diguinho.Max

boa noite galera,
estou com o seguinte problema,
quando tento acessar o banco de dados o metodo está me retornando null e ai da exceção nullPointerExeption, pois acho que nao está criando a concxao JTA.
alguem pod me da uma luz.

LOG JBOSS
20:02:34,439 INFO  [org.springframework.transaction.jta.JtaTransactionManager] (MSC service thread 1-2) Using JTA UserTransaction: Transaction: unknown
20:02:34,439 AVISO [org.springframework.transaction.jta.JtaTransactionManager] (MSC service thread 1-2) No JTA TransactionManager found: transaction suspension not available
20:02:34,440 INFO  [org.springframework.transaction.jta.JtaTransactionManager] (MSC service thread 1-2) Using JTA TransactionSynchronizationRegistry: com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple@259f1b1d
20:02:34,472 INFO  [org.springframework.web.context.ContextLoader] (MSC service thread 1-2) Root WebApplicationContext: initialization completed in 1305 ms
GRAVE [javax.enterprise.resource.webcontainer.jsf.application] (http--127.0.0.1-80-1) Error Rendering View[/visao/cadastroCliente.xhtml]: javax.el.ELException: /visao/cadastroCliente.xhtml @27,62 value="#{pessoaVisao.listaTPessoa}": java.lang.NullPointerException
by: java.lang.NullPointerException at br.org.tcc.view.PessoaVisao.getListaTPessoa(PessoaVisao.java:312) [classes:]
meu persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
	<persistence-unit name="sgp-PU" transaction-type="JTA">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jta-data-source>java:/OracleDS</jta-data-source>
		<properties>
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.format_sql" value="true" />
		</properties>
		<!-- exclude-unlisted-classes>true</exclude-unlisted-classes -->
	</persistence-unit>
</persistence>
Spring contexr.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:util="http://www.springframework.org/schema/util" 
	xmlns:jee="http://www.springframework.org/schema/jee"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd 
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"
	default-autowire="byName">

	<jee:jndi-lookup id="entityManagerFactory" jndi-name="sgp-PU" />
	<bean name="txManager"
		class="org.springframework.transaction.jta.JtaTransactionManager">
	</bean>
	<tx:advice id="txAdvice" transaction-manager="txManager">
		<tx:attributes>
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="*" propagation="SUPPORTS" />
		</tx:attributes>
	</tx:advice>
	<aop:config>
		<aop:pointcut id="defaultServiceOperation"
	expression="execution(* br.org.tcc.service.*Service.*(..))" />
		<aop:advisor pointcut-ref="defaultServiceOperation"
			advice-ref="txAdvice" />
	</aop:config>

	<bean name="databaseRole" class="java.lang.String">
		<constructor-arg>
			<value>${database.role}</value>
		</constructor-arg>
	</bean>
	<bean name="databaseRoleEnabled" class="java.lang.Boolean">
		<constructor-arg>
			<value>${database.role.enabled}</value>
		</constructor-arg>
	</bean>
</beans>
meu Spring Application
<?xml version="1.0" encoding="ISO-8859-1"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.1.xsd"
	default-autowire="byName">
	
	<context:component-scan base-package="br.org.tcc" />
	<import resource="spring-context.xml" />
</beans>
meu web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee" id="WebApp_ID"
	version="2.5">
	<display-name>SGPJ</display-name>
	<welcome-file-list>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.xhtml</welcome-file>
	</welcome-file-list>

	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.jsf</url-pattern>
	</servlet-mapping>

	<context-param>
		<param-name>org.richfaces.skin</param-name>
		<param-value>blueSky</param-value>
	</context-param>

	<context-param>
		<param-name>org.richfaces.control_skinning</param-name>
		<param-value>disable</param-value>
	</context-param>

	<context-param>
		<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
		<param-value>.xhtml</param-value>
	</context-param>

	<persistence-unit-ref>
		<description>Persistence unit da aplicacao</description>
		<persistence-unit-ref-name>sgp-PU</persistence-unit-ref-name>
		<persistence-unit-name>sgp-PU</persistence-unit-name>
	</persistence-unit-ref>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>WEB-INF/spring-application.xml</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener
		</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.context.request.RequestContextListener
		</listener-class>
	</listener>
</web-app>
Criado 18 de março de 2012
Respostas 0
Participantes 1