-->
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: session filter can't work:query must begin with SELECT or FR
PostPosted: Thu Feb 24, 2005 1:06 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

2.1.6:

<class name="com.test.bean.Broker" table="broker" dynamic-update="true" dynamic-insert="true">
<id name="broker_id" column="broker_id" type="string">
<generator class="com.test.util.HibernateGenerator"/>
</id>
<property name="city">
<column name="city" sql-type="varchar(20)"/>
</property>

<set name="brokers" inverse="true" lazy="true">
<key column="broker_id"/>
<one-to-many class="com.fangtoo.bean.Broker"/>
</set>
</class>:


Session s=HibernateUtil.currentSession();
Transaction t=s.beginTransaction();

Broker boss=(Broker)s.get(Broker.class,"743");
Set brokers=boss.getBrokers();
log.info("boss is: "+brokers);
Broker bb=(Broker)s.filter(brokers,"this.broker_type='boss'");
log.info("boss name is : "+bb.getBrief_name());
t.commit();
HibernateUtil.closeSession();


12:38:33,953 INFO TestHiber:50 - boss is: [com.fangtoo.bean.Broker@691dee]
net.sf.hibernate.QueryException: query must begin with SELECT or FROM: this.broker_type [this.broker_type='boss']
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:84)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.hql.FilterTranslator.compile(FilterTranslator.java:26)
at net.sf.hibernate.impl.SessionFactoryImpl.getFilter(SessionFactoryImpl.java:306)
at net.sf.hibernate.impl.SessionImpl.getFilterTranslator(SessionImpl.java:3456)
at net.sf.hibernate.impl.SessionImpl.filter(SessionImpl.java:3513)
at net.sf.hibernate.impl.SessionImpl.filter(SessionImpl.java:3408)
at com.fangtoo.tests.TestHiber.main(TestHiber.java:51)
Exception in thread "main"


MySQL 4.01 innoDB:

no

INFO:


Hi everyone:

I want to filter a collection that querey from database. But the filter report error:

Code:
query must begin with SELECT or FROM: this.broker_type [this.broker_type='boss']

I have seen Hibernate In Action. It write filter code in this way:
Code:
Object o=session.filter(parent.getChildSet(),"this.user_name='lyo'");

But why it can't work in my code ? Thks!

_________________
You are not alone...


Top
 Profile  
 
 Post subject: paste error
PostPosted: Thu Feb 24, 2005 1:14 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
I find that if the code is:
Code:
Object bb=s.createFilter(brokers,"this.broker_type='boss'");

It can work well and not exception.
But if the code is the following , it will report Exception:
Code:
Object bb=s.createFilter(brokers,"this.broker_type='boss'").uniqueRequest();


Does "uniqueResult" can't be used with hibernate filter?

_________________
You are not alone...


Top
 Profile  
 
 Post subject: :(
PostPosted: Thu Feb 24, 2005 8:58 pm 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
any idea?

_________________
You are not alone...


Top
 Profile  
 
 Post subject: Re: :(
PostPosted: Thu Feb 24, 2005 9:48 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
Filters filter collections, as I understand it. Why would you use a filter to get a unique result? If you know the criteria to get a single row, use that instead of a filter.


Top
 Profile  
 
 Post subject: Re: :(
PostPosted: Mon Feb 28, 2005 6:05 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
mgreer wrote:
Filters filter collections, as I understand it. Why would you use a filter to get a unique result? If you know the criteria to get a single row, use that instead of a filter.


Thks for your reply. But I want to know if hibernate filter can do this. And why it throws Exception. Sometimes it is important to filter a unique result from a collection.

_________________
You are not alone...


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.