Solved

Nullpointer exception Hibernate

Posted on 2010-09-02
11
396 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
  • 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoresClump  challenge 31 108
how to use external config file with Spring MVC 4 61
bunnyEars2 challenge 6 68
strCopies  challenge 17 73
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 …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now