-->
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: Simple HQL question
PostPosted: Fri Nov 18, 2005 1:45 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
I can search within the properties of the scholarship table just fine but queries into any of the sets arent working. Anyone know why?



Hibernate version:
hibernate-3.0.5
Mapping documents:

<hibernate-mapping>

<class name="edu.asu.SFAO.DAOs.Scholarship" table="scholarship">
<meta attribute="class-description">
A representation of an ASU scholarship
</meta>

<id name="id" column="scholarshipID" unsaved-value="0" >
<meta attribute="scope-set">protected</meta>
<generator class="native"> </generator>
</id>

<property name="name" type="string" not-null="true" column="name"> </property>
<property name="amountType" type="int" not-null="true" column="amount_type"> </property>
<property name="amount" type="int" not-null="true" column="amount"> </property>
<property name="activationDate" type="string" not-null="true" column="activation_date"> </property>
<property name="deadlineDate" type="string" not-null="true" column="deadline_date"> </property>
<property name="openDeadline" type="int" not-null="true" column="open_deadline"> </property>
<property name="applicationUrl" type="string" not-null="true" column="application_url"> </property>
<property name="needBased" type="int" not-null="true" column="need_based"> </property>
<property name="globalList" type="int" not-null="true" column="global_list"> </property>
<property name="minimumGpa" type="int" not-null="true" column="minimum_gpa"> </property>
<property name="minimumHours" type="int" not-null="true" column="minimum_hours"> </property>
<property name="azResident" type="int" not-null="true" column="az_resident"> </property>
<property name="condition" type="string" not-null="true" column="condition"> </property>
<property name="eligibility" type="string" not-null="true" column="eligibility"> </property>
<property name="description" type="string" not-null="true" column="description"> </property>
<property name="comment" type="string" not-null="true" column="comment"> </property>
<property name="contactName" type="string" not-null="true" column="contact_name"> </property>
<property name="contactOrganization" type="string" not-null="true" column="contact_organization"> </property>
<property name="contactPhone" type="string" not-null="true" column="contact_phone"> </property>

<set name="campuses" table="scholarshipXcampus" inverse="false" cascade="all">
<meta attribute="field-description">
A scholarship can have many majors associated with it
</meta>
<key column="scholarshipID"/>
<element column="campusID" type="integer"/>
</set>

<set name="classstandings" table="scholarshipXclassstanding" inverse="false" cascade="all">
<meta attribute="field-description">
A scholarship can have many classstandings associated with it
</meta>
<key column="scholarshipID" />
<element column="classstandingID" type="integer"/>
</set>

<set name="donorPrefs" table="scholarshipXdonorpref" inverse="false" cascade="all">
<meta attribute="field-description">
A scholarship can have many donor preferences associated with it
</meta>
<key column="scholarshipID" />
<element column="donorprefID" type="integer"/>
</set>

<set name="majors" table="scholarshipXmajor" inverse="false" cascade="all">
<meta attribute="field-description">
A scholarship can have many majors associated with it
</meta>
<key column="scholarshipID"/>
<element column="majorCode" type="string"/>
</set>

</class>

<query name="edu.asu.SFAO.getAllScholarships" >
<![CDATA[
from edu.asu.SFAO.DAOs.Scholarship as scholarship
order by scholarship.deadlineDate ASC
]]>
</query>

<query name="edu.asu.SFAO.getGlobalScholarships">
<![CDATA[
from edu.asu.SFAO.DAOs.Scholarship as scholarship
where scholarship.globalList=1
order by scholarship.deadlineDate ASC
]]>
</query>

<query name="edu.asu.SFAO.getActiveScholarships">
<![CDATA[
from edu.asu.SFAO.DAOs.Scholarship as scholarship
where scholarship.activationDate <= :today and scholarship.deadlineDate >= :today
order by scholarship.deadlineDate ASC
]]>
</query>

<query name="edu.asu.SFAO.getSpecificScholarship">
<![CDATA[
from edu.asu.SFAO.DAOs.Scholarship as scholarship
where scholarship.id = :id
]]>
</query>

<query name="edu.asu.SFAO.getApplicableScholarships">
<![CDATA[
from edu.asu.SFAO.DAOs.Scholarship as scholarship
where scholarship.donorPrefs = :donorPrefs
]]>
</query>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
hibScholarshipSearchSession = sessionFactory1.openSession();
scholarships = hibScholarshipSearchSession.getNamedQuery("edu.asu.SFAO.getApplicableScholarships")
.setInteger("donorPrefs",1)
.list();

Name and version of the database you are using:
ms sql (not sure of version)
The generated SQL (show_sql=true):
11:43:56,196 DEBUG SQL:324 - select scholarshi0_.scholarshipID as scholars1_, scholarshi0_.name as name3
_, scholarshi0_.amount_type as amount3_3_, scholarshi0_.amount as amount3_, scholarshi0_.activation_date
as activation5_3_, scholarshi0_.deadline_date as deadline6_3_, scholarshi0_.open_deadline as open7_3_,
scholarshi0_.application_url as applicat8_3_, scholarshi0_.need_based as need9_3_, scholarshi0_.global_l
ist as global10_3_, scholarshi0_.minimum_gpa as minimum11_3_, scholarshi0_.minimum_hours as minimum12_3_
, scholarshi0_.az_resident as az13_3_, scholarshi0_.condition as condition3_, scholarshi0_.eligibility a
s eligibi15_3_, scholarshi0_.description as descrip16_3_, scholarshi0_.comment as comment3_, scholarshi0
_.contact_name as contact18_3_, scholarshi0_.contact_organization as contact19_3_, scholarshi0_.contact_
phone as contact20_3_ from scholarship scholarshi0_, scholarshipXdonorpref donorprefs1_ where scholarshi
0_.scholarshipID=donorprefs1_.scholarshipID and .=?

Debug level Hibernate log excerpt:

11:43:56,387 WARN JDBCExceptionReporter:71 - SQL Error: 170, SQLState: 37000
11:43:56,389 ERROR JDBCExceptionReporter:72 - Line 1: Incorrect syntax near '='.
11:43:56,396 WARN JDBCExceptionReporter:48 - SQL Warning: 170, SQLState: 37000
11:43:56,397 WARN JDBCExceptionReporter:49 - Preparing the statement failed: Line 1: Incorrect syntax n


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 2:58 pm 
Beginner
Beginner

Joined: Tue Feb 01, 2005 5:26 pm
Posts: 24
Location: dallas
remove the aliases it will work.

Code:
<query name="edu.asu.SFAO.getApplicableScholarships">
<![CDATA[
from edu.asu.SFAO.DAOs.Scholarship
where donorPrefs = :donorPrefsIn
]]>
</query>


if this helps you, dont forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 12:48 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
While this does remove the error I never seem to get any results either. here is the SQL.

10:45:30,051 DEBUG SQL:324 - select scholarshi0_.scholarshipID as scholars1_, scholarshi0_.name as
name3_, scholarshi0_.amount_type as amount3_3_, scholarshi0_.amount as amount3_, scholarshi0_.act
ivation_date as activation5_3_, scholarshi0_.deadline_date as deadline6_3_, scholarshi0_.open_dead
line as open7_3_, scholarshi0_.application_url as applicat8_3_, scholarshi0_.need_based as need9_3
_, scholarshi0_.global_list as global10_3_, scholarshi0_.minimum_gpa as minimum11_3_, scholarshi0_
.minimum_hours as minimum12_3_, scholarshi0_.az_resident as az13_3_, scholarshi0_.condition as con
dition3_, scholarshi0_.eligibility as eligibi15_3_, scholarshi0_.description as descrip16_3_, scho
larshi0_.comment as comment3_, scholarshi0_.contact_name as contact18_3_, scholarshi0_.contact_org
anization as contact19_3_, scholarshi0_.contact_phone as contact20_3_ from scholarship scholarshi0
_ where scholarshi0_.scholarshipID=?


I notice its not selecting info from any of the sets, including the one I was trying to search in. Anyone know why?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 1:44 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Hibernate 3 uses lazy-loading by default. So none of ur collections are getting loaded/initialized. set lazy="true" onto the collections that you want to initialize or set lazy="true" on the class-level for all collections in that class


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 7:15 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 3:30 pm
Posts: 25
Thanks for the replies thus far guys. I am however stil not quite there. I set lazy="true" and reran it with no change in results. I thought about it then and I started to think I didnt want lazy ON, I wanted it OFF, I wanted those sets to be loaded each time so I turned lazy="false" .. and still nothing. Is this a lazy issue? Is my lazy command being ignored?

<?xml version="1.0" encoding="UTF-8"?>

<!--
Document : Scholarship.hbm.xml
Created on : March 1, 2005, 1:42 PM
Author : dsobiera
Description:
Purpose of the document follows.
-->

<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="edu.asu.SFAO.DAOs.Scholarship" table="scholarship" lazy="false">
<meta attribute="class-description">
A representation of an ASU scholarship
</meta>

<id name="id" column="scholarshipID" unsaved-value="0" >
<meta attribute="scope-set">protected</meta>
<generator class="native"> </generator>
</id>

<property name="name" type="string" not-null="true" column="name"> </property>
<property name="amountType" type="int" not-null="true" column="amount_type"> </property>
<property name="amount" type="int" not-null="true" column="amount"> </property>
<property name="activationDate" type="string" not-null="true" column="activation_date"> </property>
<property name="deadlineDate" type="string" not-null="true" column="deadline_date"> </property>
<property name="openDeadline" type="int" not-null="true" column="open_deadline"> </property>
<property name="applicationUrl" type="string" not-null="true" column="application_url"> </property>
<property name="needBased" type="int" not-null="true" column="need_based"> </property>
<property name="globalList" type="int" not-null="true" column="global_list"> </property>
<property name="minimumGpa" type="int" not-null="true" column="minimum_gpa"> </property>
<property name="minimumHours" type="int" not-null="true" column="minimum_hours"> </property>
<property name="azResident" type="int" not-null="true" column="az_resident"> </property>
<property name="condition" type="string" not-null="true" column="condition"> </property>
<property name="eligibility" type="string" not-null="true" column="eligibility"> </property>
<property name="description" type="string" not-null="true" column="description"> </property>
<property name="comment" type="string" not-null="true" column="comment"> </property>
<property name="contactName" type="string" not-null="true" column="contact_name"> </property>
<property name="contactOrganization" type="string" not-null="true" column="contact_organization"> </property>
<property name="contactPhone" type="string" not-null="true" column="contact_phone"> </property>

<set name="campuses" table="scholarshipxcampus" inverse="false" cascade="all" lazy="false" >
<meta attribute="field-description">
A scholarship can have many majors associated with it
</meta>
<key column="scholarshipID"/>
<element column="campusID" type="integer"/>
</set>

<set name="classstandings" table="scholarshipxclassstanding" inverse="false" cascade="all" lazy="false">
<meta attribute="field-description">
A scholarship can have many classstandings associated with it
</meta>
<key column="scholarshipID" />
<element column="classstandingID" type="integer"/>
</set>

<set name="donorPrefs" table="scholarshipxdonorpref" inverse="false" cascade="all" lazy="false">
<meta attribute="field-description">
A scholarship can have many donor preferences associated with it
</meta>
<key column="scholarshipID" />
<element column="donorprefID" type="integer"/>
</set>

<set name="majors" table="scholarshipxmajor" inverse="false" cascade="all" lazy="false">
<meta attribute="field-description">
A scholarship can have many majors associated with it
</meta>
<key column="scholarshipID"/>
<element column="majorCode" type="string"/>
</set>

</class>


<query name="edu.asu.SFAO.getApplicableScholarships">
<![CDATA[
from edu.asu.SFAO.DAOs.Scholarship
where donorPrefs = :donorPrefs
]]>
</query>

</hibernate-mapping>


Here is the SQL Debug.


17:10:42,201 DEBUG SQL:324 - select scholarshi0_.scholarshipID as scholars1_, scholarshi0_.name as name3_, scholar
shi0_.amount_type as amount3_3_, scholarshi0_.amount as amount3_, scholarshi0_.activation_date as activation5_3_,
scholarshi0_.deadline_date as deadline6_3_, scholarshi0_.open_deadline as open7_3_, scholarshi0_.application_url a
s applicat8_3_, scholarshi0_.need_based as need9_3_, scholarshi0_.global_list as global10_3_, scholarshi0_.minimum
_gpa as minimum11_3_, scholarshi0_.minimum_hours as minimum12_3_, scholarshi0_.az_resident as az13_3_, scholarshi0
_.condition as condition3_, scholarshi0_.eligibility as eligibi15_3_, scholarshi0_.description as descrip16_3_, sc
holarshi0_.comment as comment3_, scholarshi0_.contact_name as contact18_3_, scholarshi0_.contact_organization as c
ontact19_3_, scholarshi0_.contact_phone as contact20_3_ from scholarship scholarshi0_ where scholarshi0_.scholarsh
ipID=?


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.