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: Need some guidance for Hibernate Named Queries...
PostPosted: Tue May 16, 2006 3:27 am 
Newbie

Joined: Tue May 16, 2006 3:05 am
Posts: 3
Hi there!

I am working on a project to upgrade it to hibernate 3.1 from hibernate 2.1.

I am not basically a Java person. So, might not be able to provide u the exact information u might be looking for...

I have managed to fix other problems apart from the one I am having with the following queries in my hibernate code...

@hibernate.query name="Review.for.Meeting" query="from
Review where meeting = ?"

and

@hibernate.query name="Review.for.AgendaCategory" query="from
Review where agendaCategory = ?"

where, Review is a bean with instances of Meeting and AgendaCategory classes as members.

The hibernate-mapping looks like:
<hibernate-mapping>
<class name="Review" table="review" lazy="false">
<id name="id" column="review_id" type="java.lang.Integer" unsaved-value="0">
<generator class="native">
</generator>
</id>

<version name="version" column="version" type="int"/>

<many-to-one name="case" class="Case" cascade="none" outer-join="auto" update="true" insert="true" column="case_id"/>

<many-to-one name="meeting" class="Meeting" cascade="none" outer-join="auto" update="true" insert="true" column="meeting_id"/>

<many-to-one name="agendaCategory" class="AgendaCategory" cascade="none" outer-join="auto" update="true" insert="true" column="agenda_category_id"/>

<property name="sequence" type="java.lang.Integer" update="true" insert="true" column="sequence"/>

<property name="minutes" type="java.lang.String" update="true" insert="true" column="minutes"/>

</class>

<query name="Review.for.Case"><![CDATA[from Review where case = ?]]></query>
<query name="Review.for.Meeting"><![CDATA[from Review where meeting = ?]]></query>
<query name="Review.for.AgendaCategory"><![CDATA[from Review where agendaCategory = ?]]></query>

</hibernate-mapping>

The first query works well without any problem. But, for the other two, the exception I get is:

[16/05/06 05:11:55:969 GMT] 648c1dc5 JDBCException W org.hibernate.util.JDBCExceptionReporter SQL Error: 207, SQLState: 42S22
[16/05/06 05:11:55:969 GMT] 648c1dc5 JDBCException E org.hibernate.util.JDBCExceptionReporter [IBM][SQLServer JDBC Driver][SQLServer]Invalid column name 'agendaCategory'.
[16/05/06 05:11:55:969 GMT] 648c1dc5 JDBCException W org.hibernate.util.JDBCExceptionReporter SQL Error: 8180, SQLState: HY000
[16/05/06 05:11:55:969 GMT] 648c1dc5 JDBCException E org.hibernate.util.JDBCExceptionReporter [IBM][SQLServer JDBC Driver][SQLServer]Statement(s) could not be prepared.

I couldn't find any specific help for this in the migration document as well as in search results on google/hibernate...

Can anyone help me with the problem?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 1:36 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Your query should look like this:
from Review as r where r.agendaCategory.someAgendaProperty = ?

Reason: agendaProperty is not a column indeed, the value is an object that is stored in a separate table and Hibernate need to create a proper SQL join between two tables.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 6:28 pm 
Newbie

Joined: Tue May 16, 2006 3:05 am
Posts: 3
Hi kgignatyev,
Thanks for your prompt reply!
I am still failing to understand that if the same query was working well in Hibernate 2.1 then what is the reason it is not working with 3.1?
Because, the syntax you have suggested is a comman HQL/SQL syntax to be used.
Please correct me if I am wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 7:00 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
3.1 got new HQL parser. You still can use old parser if you will configure Hibernate to use 'classic' Session
http://www.hibernate.org/250.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 12:22 am 
Newbie

Joined: Tue May 16, 2006 3:05 am
Posts: 3
Hi kgignatyev,
Sorry, forgot to mention that I am using the old HQL parser!


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.