salut tout le monde,
ça fé pas mal de jours que je me prend la tete sur une erreur qui doit etre assez facile à résoudre.
Toutefois je suis débutant en java.
Je suis dans le cas d'un développement d'une appli web
je pense avoir repérer l'erreur mais je ne suis pas sur donc j'ai besoin de vous!!!
je vous met le code dela factory que j'implémente:
en vert foncé c 'est l'erreur (j'ai tout essayé d tests de if,...)
Je vous remercie d'avance si vous arrivez à m'aiguiller.
package
com.st.mcc.wam.service;
import
java.util.List;
import
javax.persistence.EntityManager;
import
javax.persistence.EntityManagerFactory;
import
org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory;
import
org.springframework.orm.jpa.JpaTemplate;
import
org.springframework.transaction.annotation.Transactional;
import
com.st.mcc.wam.bean.Lot;
/* create a class LotFactoryImpl to implement interface LotFactory */
public
class LotFactoryImpl
implements LotFactory{
/**
Logger.
*/
private
static
final Log
LOG = LogFactory. getLog (LotFactoryImpl.
class );
private JpaTemplate
jpaTemplate;
/* object JpaTemplate(type) jpaTemplate(attribute) */
private EntityManager
entityManager;
//private EntityManagerImpl = null;
public LotFactoryImpl() {
// default constructor}
/*public RuntimeException (){
}*/
/* (non-Javadoc)* @see com.st.mcc.wam.service.CRUDLotfactory#createLot(com.st.mcc.wam.bean.Lot)
*/
@Transactional
/* an annotation */
public Lot createLot(Lot lot)
/*Create a Lot */{
LOG .debug(
"create of lot (begin)");
LOG .debug(
"id = " + lot.getLotId());
LOG .debug(
"lattice code = " + lot.getLattice_code());
LOG .debug(
"quantity = "+ lot.getQuantity());
/* try a LOG with jpaTemplate */
try {
jpaTemplate.persist(lot);
/*.persist(lot) = persistence Object(Lot) */
jpaTemplate.flush();
/* .flush = empty a memory or up to date of memory */
LOG .debug(
"create of lot (end)");
return lot;
}
/* Failure so catch an exception to runtime */
catch (RuntimeException e) {
//throw new RuntimeException("n'existe pas")
LOG .error(
"problem !");
return
null ;
}
}
/* (non-Javadoc)* @see com.st.mcc.wam.service.CRUDLotFactory#deleteLot(com.st.mcc.wam.bean.Lot)
*/
@Transactional
public
void deleteLot(Lot lot) {
//
TODO Auto-generated method stub
}
/* (non-Javadoc)* @see com.st.mcc.wam.service.CRUDLotFactory#readLot(com.st.mcc.wam.bean.Lot)
*/
@Transactional
public Lot getLot(String lotId) {
LOG .debug(
"search of lot (begin)");
LOG .debug(
"id = " + lotId);
try {
Lot lot =
jpaTemplate.find(Lot.
class , lotId);
/* .find serve to find a lot */
LOG .debug(
"search of lot (end)");
return lot;
/*find a lot so return a lot*/}
catch (RuntimeException e) {
System.
err .println(e);
LOG .error(
"problem !");
return
null ;
/* not find a lot so return null and to start again a search */}
}
/* (non-Javadoc)* @see com.st.mcc.wam.service.CRUDLotFactory#updateLot(com.st.mcc.wam.bean.Lot)
*/
@Transactional
public
void updateLot(Lot lot) {
//
TODO Auto-generated method stub
}
/*the connection at BDD = EntityManagerFactory */
public
void setEntityManagerFactory(EntityManagerFactory emf) {
this .
jpaTemplate =
new JpaTemplate(emf);
this .
entityManager = emf.createEntityManager();}
@Transactional
public List<Lot> getLots(){
//if (l!= 0) throw new RuntimeException("");
for (
int i =0; i<2; i++){
Lot l =
new Lot();l.setLotId(
"G_"+ i);l.setLattice_code(
"");l.setQuantity(3);
l.setJalon(
"");l.setTechnology(
"");l.setPriority(
"");l.setStatus_lot(
"");l.setHold(
"");l.setOverride(
"");
int date_begin = 06/02/2008;l.setDate_debut(date_begin);
l.setDate_debut(06/02/2008);
int date_end = 17/04/2008;l.setDate_fin(date_end);
this .createLot(l);
LOG .debug(
"Lot = " + l.getLotId() );}
System.
out .println(
" hello!");
//il m'affiche bien ceci sur la console d'éclipse
entityManager.createNamedQuery(
"getAllLots");
/*ERROR HERE*/
List<Lot> lotList=
jpaTemplate.find(
"SELECT * FROM LOT");
jpaTemplate.findByNamedQuery(
"getAllLots",lotList);
/**
This
is
the
list
of
object
**/
return (List<Lot>)lotList;}
/**************Properties************************/
/**
*
@return
the
jpaTemplate
*/
public JpaTemplate getJpaTemplate() {
return
jpaTemplate;}
/**
*
@param
jpaTemplate
the
jpaTemplate
to
set
*/
public
void setJpaTemplate(JpaTemplate jpaTemplate) {
this .
jpaTemplate = jpaTemplate;}
/**
*
@return
the
entityManager
*/
public EntityManager getEntityManager() {
return
entityManager;}
/**************************************************/
/**
*
@param
entityManager
the
entityManager
to
set
*/
public
void setEntityManager(EntityManager entityManager) {
this .
entityManager = entityManager;}
/**
*
@return
the
lOG
*/
public
static Log getLOG() {
return
LOG ;}
/*****************************************************/
}
voici l'erreur ke me donne internet qu'en j'exécute ma requete.
exception
javax.servlet.ServletException
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
root cause
java.lang.NullPointerException
com.st.mcc.wam.service.LotFactoryImpl.getLots(LotFactoryImpl.java:175)
com.st.mcc.wam.action.LotInfoAction.getLotInfo(LotInfoAction.java:34)
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:585)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96
voila
Afficher la suite