Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
1.0.5000.0
Mapping documents:
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
<class name="mapping.Country, mapping" table="country">
<id name="id" column="id_country" unsaved-value="0">
<generator class="sequence" />
</id>
<property name="name" column="name"/>
<set lazy="true" name="regions" inverse="true" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics">
<key column="region_id"/>
<one-to-many class="mapping.Region,mapping"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
<class name="mapping.Region, mapping" table="region">
<id name="id" column="id_region" unsaved-value="0">
<generator class="sequence" />
</id>
<property name="name" column="name"/>
<many-to-one name="country"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics"
class="mapping.Country, mapping"
column="region_id"
not-null="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Exception non gérée : NHibernate.QueryException: unexpected token: as [select c from count
ry as c]
à NHibernate.Hql.FromParser.Token(String token, QueryTranslator q)
à NHibernate.Hql.ClauseParser.Token(String token, QueryTranslator q)
à NHibernate.Hql.PreprocessingParser.Token(String token, QueryTranslator q)
à NHibernate.Hql.ParserHelper.Parse(IParser p, String text, String seperators, QueryTra
nslator q)
à NHibernate.Hql.QueryTranslator.Compile()
à NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionar
y replacements, Boolean scalar)
à NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow)
à NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)
à NHibernate.Impl.SessionImpl.Enumerable(String query, QueryParameters parameters)
à NHibernate.Impl.QueryImpl.Enumerable()
à mapping.NHDBMgr.getAllCountry() dans C:\Documents and Settings\a.UNICORNI-24064D\Mes
documents\Visual Studio 2005\Projects\mapping\mapping\NHDBMgr.cs:ligne 195
à mapping.Program.Main(String[] args) dans C:\Documents and Settings\a.UNICORNI-24064D\
Mes documents\Visual Studio 2005\Projects\mapping\mapping\Program.cs:ligne 25
Name and version of the database you are using:
Oracle version 10g
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
DEBUG
Hello
I have a problem with this code :
Code:
public ArrayList getAllCountry()
{
ArrayList a = null;
_session = _factory.OpenSession();
_transaction = _session.BeginTransaction();
IQuery query = _session.CreateQuery("select c from country as c");
foreach (Country c in query.Enumerable())
{
a.Add(c);
}
_transaction.Commit();
_session.Close();
return a;
}
I just want to select and retrieve all country in the table country. What is wrong ? How can I do that ?
Another question :
I use NHibernate in a distributed environnement with a .NET REMOTING server that use NHibernate and expose methods to .NET REMOTING clients that return business object.
Sometimes I need to return an instance of Country to clients without loading Regions and Peoples collections that are in the Country class. How to load only when needed each collection ?
I am obliged to create methods like getCountry(idCountry, boolLoadRegions, boolLoadPeople) where boolLoadRegions when is set to true init the Region collection in Country and where boolLoadPeople when is set to true init the People collection in Country or can I do that in another way ?
The problem is that I can't keep the session open and so when a client get a Country he can't access the Region collection for example because the session is close !
Thanks in advance for helping me to correct the first problems and saying me if my approch is good.
[/code]