Solved

Nullpointer exception Hibernate

Posted on 2010-09-02
11
433 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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.

728 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