Solved

Nullpointer exception Hibernate

Posted on 2010-09-02
11
429 Views
Last Modified: 2012-08-13
When I run a hibernate code I am getting the following exception. Need help please.

java.lang.NullPointerException
      at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
      at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
      at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
      at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
      at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
      at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
      at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:838)
      at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
      at org.hibernate.type.EntityType.resolve(EntityType.java:303)
      at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
      at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
      at org.hibernate.loader.Loader.doQuery(Loader.java:717)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
      at org.hibernate.loader.Loader.doList(Loader.java:2150)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
      at org.hibernate.loader.Loader.list(Loader.java:2024)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
      at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300)
      at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:146)
      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1093)
      at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
      at com.twc.soatest.dao.DigitalPhoneDAO.validateDPActivation(DigitalPhoneDAO.java:296)
      at com.twc.soatest.db.SOATestDBUtil.validateDPActivation(SOATestDBUtil.java:275)
      at com.twc.soatest.db.TestSOATest.main(TestSOATest.java:27)
0
Comment
Question by:prsubject
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 

Author Comment

by:prsubject
ID: 33594055
Some say to move from cglib to javaassist. I am having both
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33594059
can you post the following code also.
validateDPActivation method in DigitalPhoneDAO class
0
 

Author Comment

by:prsubject
ID: 33594070
public boolean validateDPActivation(String tn, Session session)
    {
        Application.showMessage("Entering validateDPActivation - DigitalPhoneDAO");
        Application.showMessage("TN retrieved from DB is "+tn);
        boolean dpActivated=false;
        List<ServiceProfile> spList = new ArrayList<ServiceProfile>();
        ServiceProfile sProfile = null;
        try {
        Query query = session.getNamedQuery("com.xxx.soatest.bsif.entity.ServiceProfile.getServiceProfileByTN");
        query.setString("tn", tn);
        spList=query.list();
       
        Application.showMessage("From DAO List size is "+spList.size());
       
       
            for(int index=0; index<spList.size();index++)
            {
                sProfile= (ServiceProfile) spList.get(index);
            }
            /*if(spList.size() > 0)
                dpActivated=true;*/
            if(sProfile!= null && sProfile.getServiceUid().equals(tn))
                dpActivated=true;
        }
        catch(Exception e) {
            e.printStackTrace();
        }
        finally {
            session.close();
        }
        Application.showMessage("From DAO List size is "+spList.size());
        System.out.println("From DAO List size is "+spList.size());
        Application.showMessage("Inside DAO class is DPActivated "+dpActivated);
        return dpActivated;
    }
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 

Author Comment

by:prsubject
ID: 33594088
I am getting list size as 0 even if data exists
From DAO List size is 0
TN Exists false

This is my query in hbm.xml file
        <query name="getServiceProfileByTN">
            <![CDATA[FROM  ServiceProfile a WHERE  a.serviceUid= :tn]]>
        </query>


0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 125 total points
ID: 33594108
For nullpointerexception while doing query.list(), please check if you have declared any nullable column as not-nullable in the mapping file.

<<I am getting list size as 0 even if data exists>>
Please check if the query that you are running (with the same substituted value) gives the same result when you run it independently
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 125 total points
ID: 33594125
Use this hibernate query editor, it will save a lot of your time and points :)
https://hqe.dev.java.net/

it gives more detailed and informative error messages
0
 

Author Comment

by:prsubject
ID: 33594136
select * from xxx sp
where sp.yyy='5124349071' is giving a record
0
 

Author Comment

by:prsubject
ID: 33594160
I downloaded the hqe The bat file is not opening up. It is displaying some error and closing

0
 

Author Comment

by:prsubject
ID: 33594163
I need to show the results today. need help please.
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 125 total points
ID: 33594448
query.setString("tn", tn); is setting the tn value which is a integer value (from your reply #33594136), please make sure if the data type use here is the correct one as per your mapping
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33594506
@prsubject: if you need help in getting this cross-checked, please post the code here, i can help in that. Or let me know if any reference is required.

Also please check, if the value you are testing with is the same value which is getting passed to the query also and to the correct column.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordlen challenge 3 88
null output 3 57
java mysql insert application 14 68
Setup GlassFish 4 55
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question