-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem of query.list()
PostPosted: Tue Sep 19, 2006 8:35 pm 
Newbie

Joined: Tue Aug 29, 2006 2:54 am
Posts: 16
I have a table named Car. It has no primary key , so in Car.hbm.xml , all columns composite PK.And all columns accept null value.
So I have two class , Car.java and CarId.java.
When I execute the following snippet.It return list size is 2 , this is correct result, but all elements in list are null.Can someone tell me how to solve this problem?


Code:
        Session session = sessionFactory.openSession();
       String Hql = "from Car where id.CarName = 'ABC'";
       Query query = session.createQuery(Hql);
       return query.list();


Last edited by avseq on Wed Sep 20, 2006 2:53 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 20, 2006 2:09 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
Could you please post the content of HBM file? Also not sure how you are browsing the data. It shall be done in following fashion

List lst = query.list();
Iterator itr = lst.iterator();
while(itr.hasNext()){

Car car = (Car) itr.next();
CarID = car.getID(); ===> This line shall give you all content

}

Let me know, if I made any mistake in above code

Sudhir


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 20, 2006 2:49 am 
Newbie

Joined: Tue Aug 29, 2006 2:54 am
Posts: 16
Thanks for your reply,the Car.hbm.xml file listed below.

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">
<!--
    Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
    <class name="com.test.Car" table="Car" schema="Owner">
        <composite-id name="id" class="com.test.CarId">
            <key-property name="carName" type="java.lang.String">
                <column name="CARNAME" length="64" />
            </key-property>
            <key-property name="carType" type="java.lang.String">
                <column name="CARTYPE" length="64" />
            </key-property>
        </composite-id>
    </class>
</hibernate-mapping>


Code:

List lst = query.list();
Iterator itr = lst.iterator();
while(itr.hasNext()){

Car car = (Car) itr.next();
CarID = car.getID(); // This will cause NullPointException , because all
                               // elements in list is null
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.