IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

EntityManager et requête Select -> NullPointerException


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2011
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 44
    Par défaut EntityManager et requête Select -> NullPointerException
    Salut à tous,

    voila pour mon application multicouches, j'essaye de lister (via ma vue) des record d'une table de ma DB. J'utilise des annotations JPA dans mes différentes classe.

    Ma classe DAOImpl
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    	@PersistenceContext
    	private EntityManager em;
     
    	@Transactional
    	public void create(Role role) {
    		Role myRole = em.merge(role);
    		em.flush();
     
    		role.setRole(myRole.getRole());
     
    	}
     
    	@Transactional(readOnly=true)
    	public List<Role> listRole() {
    		@SuppressWarnings("unchecked")
    		List<Role>mesRoles = em.createQuery("SELECT r FROM t_role r").getResultList();
    		return mesRoles;
    	}
    ...
    Ma classe de service
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    @Service
    public class RoleServiceImpl implements RoleService {
     
    	private final Log logger = LogFactory.getLog(getClass());
    	@Autowired
    	private IRoleDAO roleDao;
     
     
    	public void addRole(Role role) {
    		roleDao.create(role);
     
     
    	}
     
     
    	public List<Role> listRole() {
     
    		List<Role> roles=null;
    		try
    		{
    			roles = roleDao.listRole();
    		}
    		catch(Exception e)
    		{
    			logger.error("Problem avec la liste"+e.getMessage());
    		}
     
     
    		return roles;
    	}
    Et mon Controller
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    @Controller
    public class RoleController {
    	private final Log logger = LogFactory.getLog(getClass());
     
    	private RoleService roleService;
     
    	@RequestMapping(value="/lstroles.html")
    	public ModelAndView displayRoles(HttpServletRequest req , HttpServletResponse rep)
    	{
    		logger.info("displayRoles()");
    		ModelAndView mav = new  ModelAndView();
    		mav.setViewName("layout");
    		req.setAttribute("pageTitle", "Vos roles");
    		req.setAttribute("maingPage", "/roles/lstroles.jsp");
     
    		mav.addObject("roles", roleService.listRole());
    		return mav;
     
    	}
     
    }
    Quand je veux afficher ma page, j'ai comme message :
    12-nov.-2011 18:21:41 org.apache.catalina.core.StandardWrapperValve invoke
    GRAVE: Servlet.service() for servlet [spring] in context with path [/projetecole_login0511] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
    java.lang.NullPointerException
    at be.helb.app.controller.RoleController.displayRoles(RoleController.java:29)
    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)

    Tout est bon non ? Comment savoir si mon DAO et mon Service contiennent bien ma liste ?
    Merci d'avance

  2. #2
    Membre Expert
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 963
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 963
    Par défaut
    En cas d'exception vous renvoyez null et mav.addObject n'accepte sans doute pas null comme paramètre, comme vous avez un logger.error vous devriez voir quelque chose dans les logs à moins que vous ayez mal configuré vos paramètres de configuration du logger,
    commencez par renvoyer une liste vide au lieu de null : si çà "fonctionne", c'est que vous avez une exception qui n'est pas logguée pour cause de configuration erronée et qu'une fois que vous aurez corrigé cela, vous verrez la vraie cause du problème.

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2011
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 44
    Par défaut
    Ok, je ne vois pas grand chose concernant ma liste, ni le message d'erreur que j'ai mis dans logger.error dans le fichier.

    logs.txt
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
     
    2011-11-12 21:50:25,615 INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization started
    2011-11-12 21:50:25,679 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing Root WebApplicationContext: startup date [Sat Nov 12 21:50:25 CET 2011]; root of context hierarchy
    2011-11-12 21:50:25,772 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
    2011-11-12 21:50:26,381 INFO [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] - Loading properties file from class path resource [jdbc.properties]
    2011-11-12 21:50:26,396 INFO [org.springframework.context.weaving.DefaultContextLoadTimeWeaver] - Using a reflective load-time weaver for class loader: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
    2011-11-12 21:50:26,568 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Bean 'dataSource' of type [class org.apache.commons.dbcp.BasicDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2011-11-12 21:50:26,599 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Bean 'org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter#5029d294' of type [class org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2011-11-12 21:50:26,599 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Bean 'jpaDialectTrans' of type [class org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2011-11-12 21:50:26,615 INFO [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] - Building JPA container EntityManagerFactory for persistence unit 'projetecole'
    2011-11-12 21:50:27,552 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Bean 'entityManagerFactory' of type [class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2011-11-12 21:50:27,583 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@67e2c841: defining beans [org.springframework.context.weaving.AspectJWeavingEnabler#0,org.springframework.context.config.internalBeanConfigurerAspect,loadTimeWeaver,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,entityManagerFactory,jpaDialectTrans,transactionManager,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.transaction.config.internalTransactionAspect,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,roleDAOImpl,roleServiceImpl,org.springframework.security.providers.dao.DaoAuthenticationProvider#0,_userDetailsService,org.springframework.security.config.AuthenticationProviderBeanDefinitionParser$AuthenticationProviderCacheResolver#0,_authenticationManager,_filterChainProxy,_httpSessionContextIntegrationFilter,_filterChainProxyPostProcessor,_filterChainList,_securityContextHolderAwareRequestFilter,_accessManager,_portMapper,_exceptionTranslationFilter,_filterSecurityInterceptor,_sessionFixationProtectionFilter,_anonymousAuthenticationProvider,_anonymousProcessingFilter,_rememberMeServices,_rememberMeAuthenticationProvider,_rememberMeFilter,_rememberMeServicesInjectionBeanPostProcessor,_logoutFilter,_basicAuthenticationEntryPoint,_basicAuthenticationFilter,_formLoginFilter,_formLoginEntryPoint,_entryPointInjectionBeanPostProcessor,_userServiceInjectionPostProcessor]; root of factory hierarchy
    2011-11-12 21:50:27,770 INFO [org.springframework.security.userdetails.jdbc.JdbcUserDetailsManager] - No authentication manager set. Reauthentication of users when changing passwords will not be performed.
    2011-11-12 21:50:27,801 INFO [org.springframework.security.config.EntryPointInjectionBeanPostProcessor] - Selecting AuthenticationEntryPoint for use in ExceptionTranslationFilter
    2011-11-12 21:50:27,801 INFO [org.springframework.security.config.EntryPointInjectionBeanPostProcessor] - Using main configured AuthenticationEntryPoint.
    2011-11-12 21:50:27,801 INFO [org.springframework.security.config.EntryPointInjectionBeanPostProcessor] - Using bean 'org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint@48834af6' as the entry point.
    2011-11-12 21:50:27,817 INFO [org.springframework.security.intercept.AbstractSecurityInterceptor] - Validated configuration attributes
    2011-11-12 21:50:27,833 INFO [org.springframework.security.config.RememberMeServicesInjectionBeanPostProcessor] - Setting RememberMeServices on bean _basicAuthenticationFilter
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - Checking sorted filter chain: [org.springframework.security.context.HttpSessionContextIntegrationFilter[ order=200; ], org.springframework.security.ui.logout.LogoutFilter[ order=300; ], org.springframework.security.ui.webapp.AuthenticationProcessingFilter[ order=700; ], org.springframework.security.ui.basicauth.BasicProcessingFilter[ order=1000; ], org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter[ order=1100; ], org.springframework.security.ui.rememberme.RememberMeProcessingFilter[ order=1200; ], org.springframework.security.providers.anonymous.AnonymousProcessingFilter[ order=1300; ], org.springframework.security.ui.ExceptionTranslationFilter[ order=1400; ], org.springframework.security.ui.SessionFixationProtectionFilter[ order=1600; ], org.springframework.security.intercept.web.FilterSecurityInterceptor@477baf4]
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - Filter chain...
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - [0] - org.springframework.security.context.HttpSessionContextIntegrationFilter[ order=200; ]
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - [1] - org.springframework.security.ui.logout.LogoutFilter[ order=300; ]
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - [2] - org.springframework.security.ui.webapp.AuthenticationProcessingFilter[ order=700; ]
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - [3] - org.springframework.security.ui.basicauth.BasicProcessingFilter[ order=1000; ]
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - [4] - org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter[ order=1100; ]
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - [5] - org.springframework.security.ui.rememberme.RememberMeProcessingFilter[ order=1200; ]
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - [6] - org.springframework.security.providers.anonymous.AnonymousProcessingFilter[ order=1300; ]
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - [7] - org.springframework.security.ui.ExceptionTranslationFilter[ order=1400; ]
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - [8] - org.springframework.security.ui.SessionFixationProtectionFilter[ order=1600; ]
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - [9] - org.springframework.security.intercept.web.FilterSecurityInterceptor@477baf4
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - Checking whether login URL '/login.html' is accessible with your configuration
    2011-11-12 21:50:27,848 INFO [org.springframework.security.config.FilterChainProxyPostProcessor] - FilterChainProxy: FilterChainProxy[ UrlMatcher = org.springframework.security.util.AntUrlPathMatcher[requiresLowerCase='true']; Filter Chains: {/css/**=[], /login.html=[], /**=[org.springframework.security.context.HttpSessionContextIntegrationFilter[ order=200; ], org.springframework.security.ui.logout.LogoutFilter[ order=300; ], org.springframework.security.ui.webapp.AuthenticationProcessingFilter[ order=700; ], org.springframework.security.ui.basicauth.BasicProcessingFilter[ order=1000; ], org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter[ order=1100; ], org.springframework.security.ui.rememberme.RememberMeProcessingFilter[ order=1200; ], org.springframework.security.providers.anonymous.AnonymousProcessingFilter[ order=1300; ], org.springframework.security.ui.ExceptionTranslationFilter[ order=1400; ], org.springframework.security.ui.SessionFixationProtectionFilter[ order=1600; ], org.springframework.security.intercept.web.FilterSecurityInterceptor@477baf4]}]
    2011-11-12 21:50:27,864 INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization completed in 2249 ms
    2011-11-12 21:50:27,879 INFO [org.springframework.web.servlet.DispatcherServlet] - FrameworkServlet 'spring': initialization started
    2011-11-12 21:50:27,879 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing WebApplicationContext for namespace 'spring-servlet': startup date [Sat Nov 12 21:50:27 CET 2011]; parent: Root WebApplicationContext
    2011-11-12 21:50:27,879 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
    2011-11-12 21:50:27,974 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@49b9a538: defining beans [loginController,roleController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,viewResolver]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@67e2c841
    2011-11-12 21:50:28,036 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] - Mapped URL path [/home.html] onto handler 'loginController'
    2011-11-12 21:50:28,036 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] - Mapped URL path [/login.html] onto handler 'loginController'
    2011-11-12 21:50:28,036 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] - Mapped URL path [/denied.html] onto handler 'loginController'
    2011-11-12 21:50:28,036 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] - Mapped URL path [/lstroles.html] onto handler 'roleController'
    2011-11-12 21:50:28,161 INFO [org.springframework.web.servlet.DispatcherServlet] - FrameworkServlet 'spring': initialization completed in 282 ms
    2011-11-12 21:50:49,243 INFO [be.helb.app.controller.RoleController] - displayRoles()
    Où configure -t-on les logs ?

  4. #4
    Membre Expert
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 963
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 963
    Par défaut
    Citation Envoyé par Raph87 Voir le message
    Ok, je ne vois pas grand chose concernant ma liste, ni le message d'erreur que j'ai mis dans logger.error dans le fichier.

    logs.txt

    Où configure -t-on les logs ?
    log4j.properties
    log4j.xml

    …lire la doc du framework que vous utilisez…

Discussions similaires

  1. Résultat commençant par un chiffre avec requête SELECT
    Par nicolas.pissard dans le forum Requêtes
    Réponses: 4
    Dernier message: 02/04/2010, 13h31
  2. C'est possible dans une requête SELECT ?
    Par Kokito dans le forum Langage SQL
    Réponses: 7
    Dernier message: 15/04/2005, 16h59
  3. Insertion multiple à base de sous requête SELECT
    Par drinkmilk dans le forum Langage SQL
    Réponses: 8
    Dernier message: 14/04/2005, 16h34
  4. SQL Server 7.0 - Requête Select
    Par sangokus dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 23/03/2004, 10h32
  5. Optimisations mysql sur les requêtes SELECT: index
    Par leo'z dans le forum Débuter
    Réponses: 2
    Dernier message: 29/11/2003, 13h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo