java - Null Pointer Exception while using sum agregation -



java - Null Pointer Exception while using sum agregation -

while developing erp using spring mvc, jpa/hibernate need summing cr fields of entity opération when executing query createquery

i'm attempting sum cr fields of entity operation in mvc erp i'm building when executing query createquery null pointer exception.

i tested selectquery without sum aggregation worked well. need clarification.

com.ensi.erp.dao.operationmanagerimpl.sommescomptes

`public float sommecomptes(int... doubles) { string liste= new string(); string x; (int d : doubles) { x=integer.tostring(d); x=x.concat(","); liste=liste.concat(x); } liste=liste.substring(0, liste.length()-1); string cc =" select sum(op.cr) opération op "; system.out.println(cc); query req= em.createquery(cc); number somme=(number)req.getsingleresult(); homecoming somme.floatvalue(); } `

com.ensi.entitis.operation

`@entity @table(name="opérations") public class opération implements serializable { @id @column(name="id") private int idop; @column(name="journal") private char journal; @column(name="compte") private int compte; @column(name="libellé") private string libellé; @column(name="dateop") private date dateop; @column(name="dr") private float dr; @column(name="cr") private float cr; //getters public int getidop(){return idop;} public char getjournal(){return journal;} public int getcompte(){return compte;} public string getlibellé(){return libellé;} public date getdateop(){return dateop;} public float getdr(){return dr;} public float getcr(){return cr;} //setters public opération(){}; public opération(int id,char j,int com,string lib, date da ,float drr,float crr){idop=id;journal=j;compte=com;libellé=lib;dateop=da;dr=drr;cr=crr;}; public void setidop(int op){idop=op;} public void setjournal(char op){journal=op;} public void setcompte(int op){compte=op;} public void setlibellé(string op){libellé=op;} public void setdateop(date op){dateop=op;} public void setdr(float op){ dr=op;} public void setcr(float op){ cr=op;} }`

com.ensi.metier.construirebilanimpl

package com.ensi.erp.metier; import org.springframework.transaction.annotation.transactional; import com.ensi.erp.dao.operationmanager; @transactional public class construirebilanimpl implements construirebilan { private operationmanager opmanimpl2 ; private float immobilisations_corporelles=sommecomptes(1266,1322); private float immobilisation_corporelles; private float immobilisations_financieres; private float actifs_immobilisés; private float autres_actifs_nc; private float stocks; private float clients_et_comptes_rattachés; private float autres_actifs_courants; private float placements_et_autres; private float liquidités_et_equivalents; private float total_actifs_courants; private float capitaux_propres; private float capital_social; private float réserves; private float autres_capitaux_propres; private float résultat_reporté; private float total_avant_résultat; private float résultat_exercice; private float total_capitaux_propres; private float emprunts; private float autres_passifs_financiers; private float provisions; private float total_passifs_nc; private float fournisseurs_et_comptes_rattachés; private float autres_passifs_courants; private float concours_bancaires_et_autres; private float passifs_financiers; public construirebilanimpl(){}; public void setopmanimpl2(operationmanager x){opmanimpl2=x;} public float sommecomptes(int... doubles){ homecoming opmanimpl2.sommecomptes(doubles); } public float getimmobilisations_corporelles(){return immobilisations_corporelles;} public void setimmobilisations_corporelles(float x){immobilisations_corporelles=x;} }

stacktrace

info : org.springframework.web.context.contextloader - root webapplicationcontext: initialization started info : org.springframework.web.context.support.xmlwebapplicationcontext - refreshing root webapplicationcontext: startup date [sun jun 22 20:55:39 cest 2014]; root of context hierarchy info : org.springframework.beans.factory.xml.xmlbeandefinitionreader - loading xml bean definitions url [file:/c:/users/housseminfo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/erp_pcd/web-inf/classes/root-context.xml] info : org.springframework.context.annotation.classpathbeandefinitionscanner - jsr-250 'javax.annotation.managedbean' found , supported component scanning info : org.springframework.context.annotation.classpathbeandefinitionscanner - jsr-330 'javax.inject.named' annotation found , supported component scanning info : org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor - jsr-330 'javax.inject.inject' annotation found , supported autowiring info : org.springframework.beans.factory.support.defaultlistablebeanfactory - pre-instantiating singletons in org.springframework.beans.factory.support.defaultlistablebeanfactory@1888c363: defining beans [datasource,persistenceunitmanager,entitymanagerfactory,transactionmanager,operationmanager,opser,operationmanager2,bilan,org.springframework.aop.config.internalautoproxycreator,org.springframework.transaction.annotation.annotationtransactionattributesource#0,org.springframework.transaction.interceptor.transactioninterceptor#0,org.springframework.transaction.config.internaltransactionadvisor,operationcontroller,homecontroller,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.context.annotation.configurationclasspostprocessor.importawareprocessor]; root of mill hierarchy info : org.springframework.beans.factory.support.defaultlistablebeanfactory - destroying singletons in org.springframework.beans.factory.support.defaultlistablebeanfactory@1888c363: defining beans [datasource,persistenceunitmanager,entitymanagerfactory,transactionmanager,operationmanager,opser,operationmanager2,bilan,org.springframework.aop.config.internalautoproxycreator,org.springframework.transaction.annotation.annotationtransactionattributesource#0,org.springframework.transaction.interceptor.transactioninterceptor#0,org.springframework.transaction.config.internaltransactionadvisor,operationcontroller,homecontroller,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.context.annotation.configurationclasspostprocessor.importawareprocessor]; root of mill hierarchy error: org.springframework.web.context.contextloader - context initialization failed org.springframework.beans.factory.beancreationexception: error creating bean name 'bilan' defined in url [file:/c:/users/housseminfo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/erp_pcd/web-inf/classes/root-context.xml]: instantiation of bean failed; nested exception org.springframework.beans.beaninstantiationexception: not instantiate bean class [com.ensi.erp.metier.construirebilanimpl]: constructor threw exception; nested exception java.lang.nullpointerexception @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:1011) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:957) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:490) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:461) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:607) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:932) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:479) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:383) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:283) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:112) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4961) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5455) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1559) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1549) @ java.util.concurrent.futuretask$sync.innerrun(unknown source) @ java.util.concurrent.futuretask.run(unknown source) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ java.lang.thread.run(unknown source) caused by: org.springframework.beans.beaninstantiationexception: not instantiate bean class [com.ensi.erp.metier.construirebilanimpl]: constructor threw exception; nested exception java.lang.nullpointerexception @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:163) @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:87) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:1004) ... 23 more caused by: java.lang.nullpointerexception @ com.ensi.erp.metier.construirebilanimpl.sommecomptes(construirebilanimpl.java:48) @ com.ensi.erp.metier.construirebilanimpl.<init>(construirebilanimpl.java:11) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:148) ... 25 more juin 22, 2014 8:55:40 pm org.apache.catalina.core.standardcontext listenerstart grave: exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.contextloaderlistener org.springframework.beans.factory.beancreationexception: error creating bean name 'bilan' defined in url [file:/c:/users/housseminfo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/erp_pcd/web-inf/classes/root-context.xml]: instantiation of bean failed; nested exception org.springframework.beans.beaninstantiationexception: not instantiate bean class [com.ensi.erp.metier.construirebilanimpl]: constructor threw exception; nested exception java.lang.nullpointerexception @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:1011) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:957) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:490) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:461) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:607) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:932) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:479) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:383) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:283) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:112) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4961) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5455) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1559) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1549) @ java.util.concurrent.futuretask$sync.innerrun(unknown source) @ java.util.concurrent.futuretask.run(unknown source) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ java.lang.thread.run(unknown source) caused by: org.springframework.beans.beaninstantiationexception: not instantiate bean class [com.ensi.erp.metier.construirebilanimpl]: constructor threw exception; nested exception java.lang.nullpointerexception @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:163) @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:87) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiatebean(abstractautowirecapablebeanfactory.java:1004) ... 23 more caused by: java.lang.nullpointerexception @ com.ensi.erp.metier.construirebilanimpl.sommecomptes(construirebilanimpl.java:48) @ com.ensi.erp.metier.construirebilanimpl.<init>(construirebilanimpl.java:11) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:148) ... 25 more

reading stack trace, should obvious you. stack trace tells happens:

java.lang.nullpointerexception @ com.ensi.erp.metier.construirebilanimpl.sommecomptes(construirebilanimpl.java:48) @ com.ensi.erp.metier.construirebilanimpl.<init>(construirebilanimpl.java:11)

so error happens when calling sommecomptes(), happens when constructing instance of construirebilanimpl.

let's @ code:

private operationmanager opmanimpl2 ; // opmanimpl2 null. private float immobilisations_corporelles = sommecomptes(1266,1322) public float sommecomptes(int... doubles){ homecoming opmanimpl2.sommecomptes(doubles); // ^-- what's value of opmanimpl2 again? }

so, has absolutely no relation jpql queries. stack traces provide extremely valuable information. larn read , understand them.

side note: please don't utilize accents in variable , method names. stick ascii characters. , respect java naming conventions. classes start uppercase letter. , don't name doubles array of integers.

java spring hibernate jpa

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -