wariows 17 de set. de 2008
põe a stacktrace inteira… se possível o struts.xml e a action que vc tá tentando acessar
euripedes_jr 18 de set. de 2008
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- Esse é o arquivo de configuração, onde ficam as informações como:
actions, forwards, interceptors, plugins, etc. -->
<struts>
<!-- necessário para reconhecer os métodos internos da action -->
<constant name= "struts.enable.DynamicMethodInvocation" value= "true" />
<!-- Habilita o modo de desenvolvimento, útil para fazer debug -->
<constant name= "struts.devMode" value= "false" />
<package name= "br.org.trisoft.actions" namespace= "/" extends= "struts-default" >
<action name= "Index" class= "br.org.trisoft.actions.Index" >
<result name= "success" > /pages/welcome.jsp</result>
</action>
</package>
<package name= "Estoque" namespace= "/" extends= "tiles-default" >
<action name= "Estoque" class= "br.org.trisoft.actions.EstoqueAction" method= "list" >
<!-- definindo os resultados -->
<result name= "deleteOk" type= "redirect" > Estoque.action</result>
<result name= "saveOk" type= "redirect" > Estoque.action</result>
<result name= "list" type= "tiles" > estoque.list</result>
<result name= "input" type= "tiles" > estoque.form</result>
</action>
</package>
<package name= "Fabricante" namespace= "/" extends= "tiles-default" >
<action name= "Fabricante" class= "br.org.trisoft.actions.FabricanteAction" method= "list" >
<!-- definindo os resultados -->
<result name= "deleteOk" type= "redirect" > Fabricante.action</result>
<result name= "saveOk" type= "redirect" > Fabricante.action</result>
<result name= "list" type= "tiles" > fabricante.list</result>
<result name= "input" type= "tiles" > fabricante.form</result>
</action>
</package>
</struts>
FabricanteAction
package br.org.trisoft.actions ;
import java.util.List ;
import org.apache.struts2.interceptor.validation.SkipValidation ;
import br.org.trisoft.business.FabricanteBusiness ;
import br.org.trisoft.vo.Fabricante ;
import com.opensymphony.xwork2.ActionSupport ;
import com.opensymphony.xwork2.validator.annotations.Validation ;
import com.opensymphony.xwork2.validator.annotations.VisitorFieldValidator ;
@Validation
public class FabricanteAction extends ActionSupport {
//--------------------------------------------------------------------------
private static final long serialVersionUID = 6229186240009727676L ;
//--------------------------------------------------------------------------
// uso interno apenas na classe action
private FabricanteBusiness FabricanteBusiness ;
//--------------------------------------------------------------------------
// utilizado e referenciado na interface
private Fabricante fabricante ;
private List FabricanteList ;
private Integer id ;
//--------------------------------------------------------------------------
// construtor da classe
public FabricanteAction () {
// inicializando os DAO
this . FabricanteBusiness = new FabricanteBusiness ();
}
//--------------------------------------------------------------------------
// @BEGIN: métodos action da classe
public String execute () throws Exception {
return "list" ;
}
public String insert () throws Exception {
FabricanteBusiness . inserir ( fabricante );
return "input" ;
}
public String save () throws Exception {
FabricanteBusiness . altera ( id , fabricante );
return "saveOk" ;
}
public String delete () throws Exception {
FabricanteBusiness . remove ( id );
return "deleteOk" ;
}
// ignora a validação
@SkipValidation
public String list () throws Exception {
FabricanteList = FabricanteBusiness . listar ();
return "list" ;
}
public String edit () throws Exception {
fabricante = FabricanteBusiness . pesquisar ( id , fabricante );
return "input" ;
}
public String add () throws Exception {
fabricante = new Fabricante ();
return "input" ;
}
// sets e gets
public List getFabricanteList () {
if ( null == FabricanteList )
FabricanteList = FabricanteBusiness . listar ();
return FabricanteList ;
}
public Integer getId () {
return id ;
}
public void setId ( Integer id ) {
this . id = id ;
}
// visita o objeto para realizar a validação
@VisitorFieldValidator ( message = "" )
public Fabricante getFabricante () {
return fabricante ;
}
public void setCliente ( Fabricante fabricante ) {
this . fabricante = fabricante ;
}
//--------------------------------------------------------------------------
}
wariows 18 de set. de 2008
euripedes_jr 18 de set. de 2008
Eu passo esse link no menu para acessar “Fabricante.action”
stack trace
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request .
exception
javax . servlet . ServletException
org . apache . struts2 . dispatcher . Dispatcher . serviceAction ( Dispatcher . java : 518 )
org . apache . struts2 . dispatcher . FilterDispatcher . doFilter ( FilterDispatcher . java : 421 )
root cause
java . lang . NullPointerException
oracle . toplink . essentials . ejb . cmp3 . EntityManagerFactoryProvider . createEntityManagerFactory ( EntityManagerFactoryProvider . java : 120 )
javax . persistence . Persistence . createEntityManagerFactory ( Persistence . java : 37 )
javax . persistence . Persistence . createEntityManagerFactory ( Persistence . java : 27 )
br . org . trisoft . persistence . FabricanteJPADAO .< init > ( Unknown Source )
br . org . trisoft . service . FabricanteServiceDAO .< init > ( Unknown Source )
br . org . trisoft . business . FabricanteBusiness . listar ( Unknown Source )
br . org . trisoft . actions . FabricanteAction . list ( Unknown Source )
sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
sun . reflect . NativeMethodAccessorImpl . invoke ( NativeMethodAccessorImpl . java : 39 )
sun . reflect . DelegatingMethodAccessorImpl . invoke ( DelegatingMethodAccessorImpl . java : 25 )
java . lang . reflect . Method . invoke ( Method . java : 597 )
com . opensymphony . xwork2 . DefaultActionInvocation . invokeAction ( DefaultActionInvocation . java : 399 )
com . opensymphony . xwork2 . DefaultActionInvocation . invokeActionOnly ( DefaultActionInvocation . java : 262 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 224 )
com . opensymphony . xwork2 . interceptor . DefaultWorkflowInterceptor . doIntercept ( DefaultWorkflowInterceptor . java : 213 )
com . opensymphony . xwork2 . interceptor . MethodFilterInterceptor . intercept ( MethodFilterInterceptor . java : 86 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
org . apache . struts2 . interceptor . validation . AnnotationValidationInterceptor . doIntercept ( AnnotationValidationInterceptor . java : 44 )
com . opensymphony . xwork2 . interceptor . MethodFilterInterceptor . intercept ( MethodFilterInterceptor . java : 86 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
com . opensymphony . xwork2 . interceptor . ConversionErrorInterceptor . intercept ( ConversionErrorInterceptor . java : 123 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
com . opensymphony . xwork2 . interceptor . ParametersInterceptor . intercept ( ParametersInterceptor . java : 161 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
com . opensymphony . xwork2 . interceptor . StaticParametersInterceptor . intercept ( StaticParametersInterceptor . java : 105 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
org . apache . struts2 . interceptor . CheckboxInterceptor . intercept ( CheckboxInterceptor . java : 83 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
org . apache . struts2 . interceptor . FileUploadInterceptor . intercept ( FileUploadInterceptor . java : 207 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
com . opensymphony . xwork2 . interceptor . ModelDrivenInterceptor . intercept ( ModelDrivenInterceptor . java : 74 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
com . opensymphony . xwork2 . interceptor . ScopedModelDrivenInterceptor . intercept ( ScopedModelDrivenInterceptor . java : 127 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
org . apache . struts2 . interceptor . ProfilingActivationInterceptor . intercept ( ProfilingActivationInterceptor . java : 107 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
org . apache . struts2 . interceptor . debugging . DebuggingInterceptor . intercept ( DebuggingInterceptor . java : 206 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
com . opensymphony . xwork2 . interceptor . ChainingInterceptor . intercept ( ChainingInterceptor . java : 115 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
com . opensymphony . xwork2 . interceptor . I18nInterceptor . intercept ( I18nInterceptor . java : 143 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
com . opensymphony . xwork2 . interceptor . PrepareInterceptor . intercept ( PrepareInterceptor . java : 115 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
org . apache . struts2 . interceptor . ServletConfigInterceptor . intercept ( ServletConfigInterceptor . java : 170 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
com . opensymphony . xwork2 . interceptor . AliasInterceptor . intercept ( AliasInterceptor . java : 123 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
com . opensymphony . xwork2 . interceptor . ExceptionMappingInterceptor . intercept ( ExceptionMappingInterceptor . java : 176 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 219 )
com . opensymphony . xwork2 . DefaultActionInvocation $ 2. doProfiling ( DefaultActionInvocation . java : 218 )
com . opensymphony . xwork2 . util . profiling . UtilTimerStack . profile ( UtilTimerStack . java : 455 )
com . opensymphony . xwork2 . DefaultActionInvocation . invoke ( DefaultActionInvocation . java : 216 )
org . apache . struts2 . impl . StrutsActionProxy . execute ( StrutsActionProxy . java : 50 )
org . apache . struts2 . dispatcher . Dispatcher . serviceAction ( Dispatcher . java : 507 )
org . apache . struts2 . dispatcher . FilterDispatcher . doFilter ( FilterDispatcher . java : 421 )
note The full stack trace of the root cause is available in the Apache Tomcat / 5.5 . 26 logs .
wariows 18 de set. de 2008
o problema é no DAO.
mostra o código do DAO e o persistence.xml
euripedes_jr 18 de set. de 2008
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= "estoque" >
<class> br.org.trisoft.vo.Cliente</class>
<class> br.org.trisoft.vo.Estoque</class>
<class> br.org.trisoft.vo.Fabricante</class>
<properties>
<property name= "toplink.logging.level" value= "WARNING" />
<property name= "toplink.jdbc.driver" value= "com.mysql.jdbc.Driver" />
<property name= "toplink.jdbc.url" value= "jdbc:mysql://127.0.0.1:3306/sysestoque" />
<property name= "toplink.jdbc.user" value= "root" />
<property name= "toplink.jdbc.password" value= "inicial415263" />
</properties>
</persistence-unit>
</persistence>
FabricanteDAO
package br.org.trisoft.persistence ;
import java.util.List ;
import br.org.trisoft.vo.Fabricante ;
public interface FabricanteDAO {
public List < Fabricante > getTodosFabricantes ();
public Fabricante getFabricante ( Integer id , Fabricante fabricante );
public void update ( Fabricante fabricante );
public void insert ( Fabricante fabricante );
public void delete ( Integer id );
}
FabricanteJPADAO
package br.org.trisoft.persistence ;
import java.util.ArrayList ;
import java.util.List ;
import javax.persistence.EntityManager ;
import javax.persistence.EntityManagerFactory ;
import javax.persistence.EntityTransaction ;
import javax.persistence.Persistence ;
import br.org.trisoft.vo.Fabricante ;
public class FabricanteJPADAO implements FabricanteDAO {
private EntityManagerFactory factory = null ;
private EntityManager manager = null ;
public FabricanteJPADAO () {
factory = Persistence . createEntityManagerFactory ( "fabricante" );
manager = factory . createEntityManager ();
}
public void delete ( Integer userId ) {
EntityTransaction transaction = manager . getTransaction ();
try {
transaction . begin ();
Fabricante fabricante = manager . find ( Fabricante . class , userId );
manager . remove ( fabricante );
transaction . commit ();
} catch ( Exception e ) {
transaction . rollback ();
System . err . println ( "Erro: " + e . getMessage ());
} finally {
manager . close ();
}
}
public Fabricante getFabricante ( Integer id , Fabricante fabricante ) {
EntityTransaction transaction = manager . getTransaction ();
Fabricante retorno = null ;
try {
transaction . begin ();
retorno = ( Fabricante ) manager . find ( Fabricante . class , id );
} catch ( Exception e ) {
transaction . rollback ();
System . err . println ( "Erro: " + e . getMessage ());
} finally {
manager . close ();
}
return retorno ;
}
public List < Fabricante > getTodosFabricantes () {
EntityTransaction transaction = manager . getTransaction ();
List < Fabricante > fabricante = new ArrayList < Fabricante > ();
try {
transaction . begin ();
fabricante = manager . createNativeQuery ( "select * from 00_tb_fabricante" ,
Fabricante . class ). getResultList ();
} catch ( Exception e ) {
transaction . rollback ();
System . err . println ( "Erro: " + e . getMessage ());
} finally {
manager . close ();
}
return fabricante ;
}
public void insert ( Fabricante fabricante ) {
EntityTransaction transaction = manager . getTransaction ();
try {
transaction . begin ();
manager . persist ( fabricante );
transaction . commit ();
} catch ( Exception e ) {
transaction . rollback ();
System . err . println ( "Erro: " + e . getMessage ());
} finally {
manager . close ();
}
}
public void update ( Fabricante fabricante ) {
EntityTransaction transaction = manager . getTransaction ();
Fabricante retorno = null ;
try {
transaction . begin ();
retorno = manager . find ( Fabricante . class , fabricante . getFabricanteId ());
retorno . setNomeFabricante ( fabricante . getNomeFabricante ());
manager . merge ( retorno );
transaction . commit ();
} catch ( Exception e ) {
transaction . rollback ();
System . err . println ( "Erro: " + e . getMessage ());
} finally {
manager . close ();
}
}
}
wariows 18 de set. de 2008
cara você tá criando uma fabrica pelo identificador “fabricante” e só tem uma unidade chamada “estoque”…
pra criar o entitymanager vc precisa passar o nome de uma persistence unit valida
wariows 18 de set. de 2008
Tenta:
public FabricanteJPADAO() {
factory = Persistence.createEntityManagerFactory("estoque");
manager = factory.createEntityManager();
}
euripedes_jr 18 de set. de 2008
ha entendi agora.
Alterei e deu certo.
Mas tipo como meu sistema vai ter varios modulos entao eu utilizo uma fabrica padrao pra todos tipo “” ou crio uma fabrica pra cada modulo?
wariows 18 de set. de 2008
se vc utilizar vários bancos, usa várias unidades…
normalmente eu uso uma unica unidade de persistencia…
euripedes_jr 18 de set. de 2008
ok , valeu muito obrigado pela ajuda!!!
t++
abraco.