On MySQL I am trying to get objects that mapped as follows
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="hibernate.UserLesson, hibernate" table="user_lesson">
<composite-id>
<key-property name="user_id" column="user_id" access="field" />
<key-property name="lesson_id" column="lesson_id" type="System.Int32" access="field" />
</composite-id>
<property name="Score" column="score"></property>
<property name="Attempts" column="attempts"></property>
<property name="ReverseAttempts" column="reverse_attempts"></property>
<property name="ReverseScore" column="reverse_score"></property>
<many-to-one name="ToLesson" class="hibernate.Lesson,hibernate" />
</class>
</hibernate-mapping>
but I am getting the following exception
Code:
[MySqlException: Unknown column 'userless0_.ToLesson' in 'field list']
MySql.Data.MySqlClient.PacketReader.CheckForError()
MySql.Data.MySqlClient.PacketReader.ReadHeader()
MySql.Data.MySqlClient.PacketReader.OpenPacket()
MySql.Data.MySqlClient.NativeDriver.ReadResult(UInt64& affectedRows, Int64& lastInsertId)
MySql.Data.MySqlClient.CommandResult.ReadNextResult(Boolean isFirst)
MySql.Data.MySqlClient.CommandResult..ctor(Driver d, Boolean isBinary)
MySql.Data.MySqlClient.NativeDriver.SendQuery(Byte[] bytes, Int32 length, Boolean consume)
MySql.Data.MySqlClient.MySqlCommand.GetNextResultSet(MySqlDataReader reader)
MySql.Data.MySqlClient.MySqlDataReader.NextResult()
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
MySql.Data.MySqlClient.MySqlCommand.System.Data.IDbCommand.ExecuteReader()
NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)
NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session)
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
NHibernate.Hql.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters)
NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
and indeed generated SQL is out of wack
Code:
2005-06-09 07:38:30,651 [964] DEBUG NHibernate.Hql.QueryTranslator [] <> - HQL: from hibernate.UserLesson as ul where ul.user_id = 2
2005-06-09 07:38:30,661 [964] DEBUG NHibernate.Hql.QueryTranslator [] <> - SQL: select userless0_.user_id as user_id, userless0_.lesson_id as lesson_id, userless0_.reverse_attempts as reverse_5_, userless0_.ToLesson as ToLesson, userless0_.reverse_score as reverse_6_, userless0_.score as score, userless0_.attempts as attempts from user_lesson userless0_ where (userless0_.user_id=2)
2005-06-09 07:38:30,661 [964] DEBUG NHibernate.Hql.QueryTranslator [] <> - HQL: from hibernate.UserLesson as ul where ul.user_id = 2
2005-06-09 07:38:30,671 [964] DEBUG NHibernate.Hql.QueryTranslator [] <> - SQL: select userless0_.user_id as user_id, userless0_.lesson_id as lesson_id, userless0_.reverse_attempts as reverse_5_, userless0_.ToLesson as ToLesson, userless0_.reverse_score as reverse_6_, userless0_.score as score, userless0_.attempts as attempts from user_lesson userless0_ where (userless0_.user_id=2)
2005-06-09 07:38:30,681 [964] INFO NHibernate.Loader.Loader [] <> - select userless0_.user_id as user_id, userless0_.lesson_id as lesson_id, userless0_.reverse_attempts as reverse_5_, userless0_.ToLesson as ToLesson, userless0_.reverse_score as reverse_6_, userless0_.score as score, userless0_.attempts as attempts from user_lesson userless0_ where (userless0_.user_id=2)
I have couple questions:
1. Is this MySQL specific bug? I am surprised to find that I cannot fetch such simple objects.
2. Do I understand it right that loading objects with Many-to-one mapping should result in a query spanning two table and I should have my -to-one object (Lesson) loaded?