You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by MavenMan <li...@163.com> on 2007/10/11 09:09:52 UTC

how to fetch only one record ?

I have fetched a record set from database.but now I want to only one record .
so I code :

//page class
import com.myspacce.domain.Company;
public Company getCom()
	{
		_session=_sessionmanager.getSession();
		return (Company)_session.createQuery("from Company where id='11'");
	}

//HTML page:
 ${com.name}
the error is:
org.hibernate.impl.QueryImpl cannot be cast to com.myspacce.domain.Company

I want to kown how to do ? 
please help me .
thanks!!
from Chinese

-- 
View this message in context: http://www.nabble.com/how-to-fetch-only-one-record---tf4605478.html#a13150571
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: how to fetch only one record ?

Posted by Josh Canfield <jo...@thedailytube.com>.
>
>
> I have fetched a record set from database.but now I want to only one
> record .
> so I code :
>

This is a Hibernate API question. You aren't actually performing the query
until you call list(), scroll(), iterate() or uniqueResult()
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Query.html

In this case it sounds like you want uniqueResult()

(Company)_session.createQuery("from Company where id='11'").uniqueResult();

Josh

On 10/11/07, MavenMan <li...@163.com> wrote:
>
>
> I have fetched a record set from database.but now I want to only one
> record .
> so I code :
>
> //page class
> import com.myspacce.domain.Company;
> public Company getCom()
>        {
>                _session=_sessionmanager.getSession();
>                return (Company)_session.createQuery("from Company where
> id='11'");
>        }
>
> //HTML page:
> ${com.name}
> the error is:
> org.hibernate.impl.QueryImpl cannot be cast to com.myspacce.domain.Company
>
> I want to kown how to do ?
> please help me .
> thanks!!
> from Chinese
>
> --
> View this message in context:
> http://www.nabble.com/how-to-fetch-only-one-record---tf4605478.html#a13150571
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.