Solved

Nullpointer exception Hibernate

Posted on 2010-09-02
11
415 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powerN  challenge 3 62
Which is the latest version of Apache Tomcatl 3 56
servlet example issue 6 38
login form jsp example 2 24
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…
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.

808 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