-->
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: SQLQuery: list has right number of entries, but all are null
PostPosted: Sat Jun 17, 2006 1:01 am 
Newbie

Joined: Sat Jun 17, 2006 12:30 am
Posts: 3
Hi,

I am attempting to use a SQLQuery to read from a view. The problem is that while the result list contains the right number of entries, all of them are null. It's as if the class that is being bound to is not being instantiated.

For example, if there are 35 rows that match the query in the database, the result list is of size 35. All of them null.

I have tried to break this down to the simplest test case:

NamedQuery:
<sql-query name="getMatchingScholars">
<return alias="s" class="edu.yale.yis.scholar.person.Person">
<return-property name="id" column="personId"/>
<return-property name="netId" column="netId"/>
<return-property name="personName.lastName" column="lastName"/>
<return-property name="personName.firstName" column="firstName"/>
<return-property
name="personName.middleName"column="middleName"/>
<return-property name="personName.suffix" column="suffix"/>

select
s.yisScholarId as personId,
s.fsaAtlasId as netId,
s.lname as lastName,
s.fname as firstName,
s.mname as middleName,
s.NameSuffix as suffix
from v_scholar_search s
where s.lname = 'Kim'
</sql-query>

Here is the code that is run:

List results = session.getNamedQuery("getMatchingScholars").list();

Other details are below.

Any insight you can provide would be greatly appreciated. Thanks for your help.

--------------------------------------------------------
Hibernate version:
3.05

Mapping documents:

<hibernate-mapping package="edu.yale.yis.scholar.person" default-access="property" default-lazy="false">

<class name="edu.yale.yis.scholar.person.Person" table="ES_PERSONS">

<id name="id" column="personId">
<generator class="native"/>
</id>

<property name="netId" type="string" column="netId"/>

<component name="personName"
class="edu.yale.yis.scholar.person.PersonName">
<property name="firstName" type="string" column="firstName"/>
<property name="middleName" type="string" column="middleName"/>
<property name="lastName" type="string" column="lastName"/>
<property name="suffix" type="string" column="suffix"/>

</component>

<joined-subclass .....


Code between sessionFactory.openSession() and session.close():

List results =
session.getNamedQuery("getMatchingScholars").list();

Name and version of the database you are using:

SQLServer 2000

The generated SQL (show_sql=true):

select
s.yisScholarId as personId,
s.fsaAtlasId as netId,
s.lname as lastName,
s.fname as firstName,
s.mname as middleName,
s.NameSuffix as suffix
from v_scholar_search s
where s.lname = 'Kim'
-----------------------------------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 17, 2006 6:40 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
One time i noticed this behaviour when one of the coulms in my composite-id was null.

So wondering if your personId is null.

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 11:18 am 
Newbie

Joined: Sat Jun 17, 2006 12:30 am
Posts: 3
Scarface,

Thanks, that seems to have been the problem. I say "seems" as I haven't been able to verify it yet. The "null" entry in the results list is no more, so I believe it has been resolved.

I am actually trying to read from a view that does not have all the data that the regular table (that the class is persisted to) has. So, it's missing some properties. Hibernate appears to be now trying to read these non-existent properties from the view.

I understand from doing some reading in this forum, that for a SQLQuery you need to have columns that match all the properties in the object that you are trying to populate. Unfortunately, I can't do that, the view only has a limited set of columns.

So, at this stage, I think I will go back to old-fashioned JDBC and just populate the object manually.

Thanks again for your help.


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.