-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Throwing Null Pointer Exception while executing native SQL
PostPosted: Thu Jul 22, 2010 6:04 am 
Newbie

Joined: Thu Jul 22, 2010 5:37 am
Posts: 3
I am using two formula field in my POJO class.
When I am using native SQL query to get information Null Pointer Exception is throwing.
Same SQL query is working fine if I executing that SQL in SQL Prompt.
HQL query is working fine. Issue is with SQL query only.

Please help me, how can I used SQL query with formula.
Sample code is given below which I am using to fetch data from database.

I am using Oracle 10g and Hibernate 3.2.6 ga.

Stack Trace
--------------------

Exception in thread "main" java.lang.NullPointerException
at org.hibernate.loader.DefaultEntityAliases.intern(DefaultEntityAliases.java:133)
at org.hibernate.loader.DefaultEntityAliases.getSuffixedPropertyAliases(DefaultEntityAliases.java:106)
at org.hibernate.loader.DefaultEntityAliases.<init>(DefaultEntityAliases.java:52)
at org.hibernate.loader.ColumnEntityAliases.<init>(ColumnEntityAliases.java:16)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.generateCustomReturns(SQLQueryReturnProcessor.java:174)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:129)
at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:137)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at com.capgent.cpt.service.database.utils.HibernateDatabaseCalls.findSpecificRecords(HibernateDatabaseCalls.java:214)
at com.capgent.cpt.service.database.utils.HibernateDatabaseCalls.main(HibernateDatabaseCalls.java:685)
2028496404Creating new session factory object org.hibernate.impl.SessionFactoryImpl@78e86614

AddHdr.java (POJO class)
-------------------------------

Code:
public class AddHdr implements Serializable
{
    /** identifier field */
    private Integer adId;   

    /** nullable persistent field */
    private String adFname;

    /** nullable persistent field */
    private String adLname;   
   
    private String adName;
   
    public AddHdr()
    {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "address_sequence")
    @SequenceGenerator(name = "address_sequence", sequenceName = "ADDRESS_SEQ")
    @Column(name = "AD_ID", unique = true, nullable = false)
    public Integer getAdId()
    {
        return this.adId;
    }

    public void setAdId(Integer adId)
    {
        this.adId = adId;
    }

    public String getAdFname()
    {
        return this.adFname;
    }

    public void setAdFname(String adFname)
    {
        this.adFname = adFname;
    }

    public String getAdLname()
    {
        return this.adLname;
    }

    public void setAdLname(String adLname)
    {
        this.adLname = adLname;
    }

    public String getAdName()
    {
       return adName;
    }

    public void setAdName(String adName)
    {
   this.adName = adName;
    }
}


Mapping File
-----------------------

AddHdr.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
    <!--
        Created by the Middlegen Hibernate plugin 2.2

        http://boss.bekk.no/boss/middlegen/
        http://www.hibernate.org/
    -->

    <class
            name="com.capgent.cpt.common.to.AddHdr"
            table="ADD_HDR"
            lazy="true"
            >

        <cache usage="read-write"/>
        <id
                name="adId"
                type="java.lang.Integer"
                column="AD_ID"
                >

            <generator class="sequence">
                   <param name="sequence">ADDRESS_SEQ</param>
             </generator>
        </id>       
         
         <property
                name="adFname"
                type="java.lang.String"
                column="AD_FNAME"
                length="50"
                />
        <property
                name="adLname"
                type="java.lang.String"
                column="AD_LNAME"
                length="50"
                />
         <property
                name="adName"
                type="java.lang.String"
                formula="AD_LNAME|| ' ' ||AD_FNAME"
                length="100"
                insert="false"
                update="false"
                />
         
    </class>
</hibernate-mapping>



Used following code to fetch data from database

String queryTable = "select * from add_hdr";
String conditions = " where ad_id =843";
List list = obj.findSpecificRecords(queryTable, conditions, AddHdr.class);

Method
---------

Code:
public List findSpecificRecords(String queryTable, String conditions, Class classObj)
    throws ServiceLocatorException, HibernateDatabaseException
    {
        Session dbSession = getDataSource();
        long time = System.currentTimeMillis();
   
        Query query = dbSession.createSQLQuery(queryTable + conditions).addEntity(conditions, classObj).setCacheable(true);
        List objectTos = query.list();
        dbSession.close();
        return objectTos;
    }


Top
 Profile  
 
 Post subject: Re: Throwing Null Pointer Exception while executing native SQL
PostPosted: Thu Jul 22, 2010 7:25 am 
Newbie

Joined: Thu Jul 22, 2010 5:56 am
Posts: 2
Hi,
I am facing same issue. Please some body post a reply urgently.

Thanks & Regards
Madhab Mahakud.


Top
 Profile  
 
 Post subject: Re: Throwing Null Pointer Exception while executing native SQL
PostPosted: Fri Jul 23, 2010 3:47 am 
Newbie

Joined: Thu Jul 22, 2010 5:37 am
Posts: 3
Please anybody help me to fix this issue.
Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Throwing Null Pointer Exception while executing native SQL
PostPosted: Tue Jul 27, 2010 2:11 am 
Newbie

Joined: Thu Jul 22, 2010 5:56 am
Posts: 2
Hi,

Issue with formula property in hbm file that create problem to return pojo object when ever using native SQLQuery.
Kindly help me as soon as possible to sort out this issue.

Thanks
Madhab


Top
 Profile  
 
 Post subject: Re: Throwing Null Pointer Exception while executing native SQL
PostPosted: Tue Jul 27, 2010 8:07 am 
Newbie

Joined: Thu Jul 22, 2010 5:37 am
Posts: 3
Same issue reported in this URL:-
http://opensource.atlassian.com/project ... e/HHH-2225

Is anybody got the solution of this issue ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.