-->
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.  [ 6 posts ] 
Author Message
 Post subject: Some data not coming back...
PostPosted: Thu Mar 22, 2007 8:56 am 
Newbie

Joined: Thu Mar 22, 2007 8:45 am
Posts: 8
Hibernate version: hibernate3

Mapping documents:hibernate.cfg.xml

Name and version of the database you are using:Oracle

Hi. I'm new to Hibernate. I did middlegen and hbm2java to create the .hbm.xml files and POJOs. Now I am trying to query the database. When I used the Hibernate and viewed the result, some are coming back as 'null' although the data exists. To make sure, I did regular connection and viewed the resultset and data exits. Please see the following.

Why does Hibernate not return all the data back? Please help.
Thank you in advance.

//////////HIBERNATE///////////////////////////////

session = HibernateUtil.getSessionFactory().openSession();
tx = session.beginTransaction();

List res2 = session.createCriteria(TblBankRate.class)
.addOrder(Order.asc("idAffiliate"))
.list();

for (int i=0; i < res2.size(); i++ ){
TblBankRate val= (TblBankRate) res2.get(i);
System.out.println(" val=" + val );
}
tx.commit();
session.close();

////////WITHOUT HIBERNATE////////////////////////
Class.forName(driver);
connection = DriverManager.getConnection(url, user, pass);
connection.setAutoCommit(true);
ret = DbUtil.queryDB(connection, "select * from tblBankRates ");
//note: the DbUtil.queryDb just gives back to me the resultset. It is my own method ...
for ( Iterator itr = ret.iterator() ; itr.hasNext();)
{
System.out.println("ret=" + itr.next() );
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 9:05 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Let's see your hbm.xml for the TblBankRate, maybe that'll shed some light.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 9:13 am 
Newbie

Joined: Thu Mar 22, 2007 8:45 am
Posts: 8
I have not changed/customerised anything after middlegen created yet. This table is crazy that it doesn't have any PK.
That's why it is putting all the columns as composite_id in this .hbm.xml, I guess...
It is a bad design....I know, but I did not do it, I promise!

Appreciate any thoughts and suggestions!


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

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

<class
name="com.model.TblBankRate"
table="tblBankRates"
>

<composite-id>
<key-property
name="idAffiliate"
column="IdAffiliate"
type="java.lang.Integer"
length="10"
/>
<key-property
name="rateId"
column="rateID"
type="int"
length="10"
/>
<key-property
name="state"
column="state"
type="java.lang.String"
length="2"
/>
<key-property
name="bankName"
column="bankName"
type="java.lang.String"
length="80"
/>
</composite-id>


<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->


</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 9:31 am 
Newbie

Joined: Thu Mar 22, 2007 8:45 am
Posts: 8
I wonder.....
Because there is no PK in this table and because all the columns are the composite key, if some of the column values are NULL, those rows are not coming back in POJO with values...?
Those columns that have the entire column values are filled are coming, I think.

How do I get around that?
Can I manipulate the .hbm.xml to force some ids to be the primary key although it is not so in the database???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 9:44 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Ya, you should never have nullable columns in your composite keys. Try just using idAffiliate and rateId as the composite key, as long as they are not nullable and uniquely identify a row.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 10:00 am 
Newbie

Joined: Thu Mar 22, 2007 8:45 am
Posts: 8
Yup. That was what it was. Thanks.
I can not believe that someone created a table without PK!!!

Thank you.


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