-->
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.  [ 8 posts ] 
Author Message
 Post subject: Query returns list of null references (No PK columns in DB)
PostPosted: Tue Jun 06, 2006 9:54 am 
Newbie

Joined: Tue Jun 06, 2006 8:30 am
Posts: 4
Problem is as follows: I have a legacy oracle db structure (that may not be changed). All the relevant tables do not have PK's and all the tables' are nullable (don't know if that's relevant).

I want to use Hibernate as a simple read-only facade to the database. When I use the hibernatetools (eclipse plugin) to generate code, i get sensible results (unfortunately I cannot attach full code/db configuration because of confidentiality). The mapping file contains a composite key containing all the columns of the DB. The Java files seem to be generated correctly - there are setters and getters for the PK in the main class and the PK class implements equals and hashCode.

Hibernate version: 3.1.3

Mapping documents:

Code between sessionFactory.openSession() and session.close():
Code:
        s.beginTransaction();
       
        Query q = s.createQuery("from MvdFpExtr as fp where fp.id.objSid = 7071642");
        List list = q.list();
        s.getTransaction().commit();


That returns a list where list.size == 1 and list.iterator().next() == null.
If I do a query that should return a number of elements, I get the correct size list but all items are null.

Name and version of the database you are using:
Oracle 9i 9.2.0.7.0

Debug level Hibernate log excerpt:

Code:
06.06.2006 15:46:31,723 [DEBUG] org.hibernate.loader.Loader : processing result set
06.06.2006 15:46:31,723 [DEBUG] org.hibernate.loader.Loader : result set row: 0
06.06.2006 15:46:31,754 [DEBUG] org.hibernate.type.BigDecimalType : returning '46' as column: JOB1_0_
06.06.2006 15:46:31,754 [DEBUG] org.hibernate.type.LongType : returning '7071642' as column: OBJ2_0_
06.06.2006 15:46:31,754 [DEBUG] org.hibernate.type.ByteType : returning '1' as column: OBJ3_0_

--snip--
Code:
06.06.2006 15:46:31,754 [DEBUG] org.hibernate.type.StringType : returning null as column: EXTERNAL11_0_
06.06.2006 15:46:31,754 [DEBUG] org.hibernate.loader.Loader : result row: null
06.06.2006 15:46:31,801 [DEBUG] org.hibernate.loader.Loader : done processing result set (1 rows)
06.06.2006 15:46:31,816 [DEBUG] org.hibernate.jdbc.AbstractBatcher : about to close ResultSet (open ResultSets: 1, globally: 1)
06.06.2006 15:46:31,816 [DEBUG] org.hibernate.jdbc.AbstractBatcher : about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
06.06.2006 15:46:31,816 [DEBUG] org.hibernate.jdbc.AbstractBatcher : closing statement
06.06.2006 15:46:31,848 [DEBUG] org.hibernate.loader.Loader : total objects hydrated: 0


As you can see, hiberante correctly reads the data from the DB, but still a null is returned. I have no idea why. No information with WARN or higher priority is written about this in the logs. I get no stack trace.

While I'm certainly not a hibernate expert, I've spent a considerable amount of time trying to solve this, and currently I assume it's a hibernate bug (i.e. returning nulls without any warning is unexpected behavior). Perhaps it occurs when there are no fields outside the composite ID.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 10:13 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
what's in the index column for that row of data?

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 10:24 am 
Newbie

Joined: Tue Jun 06, 2006 8:30 am
Posts: 4
kochcp wrote:
what's in the index column for that row of data?


How can I find that out? I'm not very experienced in dealing with DBs.

I'm using SquirrelSQL to read the (meta)data from DB, this is what is listed under the "Indexes" view at the table level:

INDEX_QUALIFIER=<null>
INDEX_NAME=<null>
ORDINAL_POSITION=0
COLUMN_NAME=<null>
ASC_OR_DESC=<null>
NON_UNIQUE=0
TYPE=0
CARDINALITY=66394
PAGES=3754
FILTER_CONDITION=<null>

there is only one row in the Indexes view.

Thanks for your answer.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 10:56 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
sorry, I don't mean the database index. If you are using the List collection from hibernate, in the mapping files (*.hbm.xml) it requires you to specify an index column for the table. If there is anything other than a 0 in that column for that particular row, that could explain why you are getting a null value.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 11:24 am 
Newbie

Joined: Tue Jun 06, 2006 8:30 am
Posts: 4
kochcp wrote:
sorry, I don't mean the database index. If you are using the List collection from hibernate, in the mapping files (*.hbm.xml) it requires you to specify an index column for the table. If there is anything other than a 0 in that column for that particular row, that could explain why you are getting a null value.


Sorry, I'm a bit lost here. The mapping file is like this (a few irrelevant things are replaced with "xxx"):
Code:
<hibernate-mapping>
    <class name="xxx" table="xxx" schema="xxx">
        <composite-id name="id" class="xxxId">
            <key-property name="jobId" type="big_decimal">
                <column name="JOB_ID" precision="22" scale="0" />
            </key-property>
            <key-property name="objSid" type="java.lang.Long">
                <column name="OBJ_SID" precision="10" scale="0" />
            </key-property>
--- SNIP ---
       </composite-id>
    </class>
</hibernate-mapping>


There is no other elements than those listed above (specifically, there are no associations defined, which is fine for now).

I did a quick search to the hibernate documentation, and specifying an index is mentioned when mapping collections (which I don't need to do here) - I didn't find other information about that there.

Also, I'm not explicitly using any hibernate-specific collections. As you can see from the code in the first post, I just ask for the results as a List (java.util.List).

I'd appreciate if you could provide a link to the relevant part of documentation or an example code snippet. I've done similar things (e.g. Middlegen + hbm2java) and never run into this problem (the difference beign that in those cases there were a single ID column defined in the DB).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 11:37 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
ohh, sorry. I thought you were dealing with a collection in a class

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 11:39 am 
Newbie

Joined: Tue Jun 06, 2006 8:30 am
Posts: 4
kochcp wrote:
ohh, sorry. I thought you were dealing with a collection in a class


That's ok, I appreciate the time you took to try to help me anyway :). Thanks for that.


Top
 Profile  
 
 Post subject: Re: Query returns list of null references (No PK columns in DB)
PostPosted: Fri Mar 12, 2010 9:02 am 
Newbie

Joined: Thu Dec 17, 2009 5:01 am
Posts: 2
Please enter all the data's in all the columns and run ur query.
This time i think u should not get null references.


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