ActiveRecord mysql view issue

27 views
Skip to first unread message

jake

unread,
Nov 4, 2009, 1:16:32 PM11/4/09
to Castle Project Users
I created a view in mysql that join several tables. I then created an
ActiveRecord object to access the view like I would a table. The
issue is that whenever I compile I get the following error:

Can not modify more than one base table through a join view
'tablename'

It looks like nhibernate is doing an update, but I don't know why, I'm
only accessing the Find function of the object. Any Ideas?

Stack Trace:
[MySqlException (0x80004005): Can not modify more than one base table
through a join view 'tablename']
MySql.Data.MySqlClient.MySqlStream.OpenPacket() +278
MySql.Data.MySqlClient.NativeDriver.ReadResult(UInt64&
affectedRows, Int64& lastInsertId) +97
MySql.Data.MySqlClient.MySqlDataReader.GetResultSet() +87
MySql.Data.MySqlClient.MySqlDataReader.NextResult() +1004
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior
behavior) +1620
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() +32
MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() +69
NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd) +61
NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation
expectation) +66
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object
id, Object[] fields, Object[] oldFields, Boolean[] includeProperty,
Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql,
ISessionImplementor session) +1906

[ADOException: could not update:
[Table.Models.Rooms.Community_Room_Client_View#15][SQL: UPDATE
viewname SET _id = ?, _id2 = ?, _id3 = ? WHERE _id4 = ?]]
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object
id, Object[] fields, Object[] oldFields, Boolean[] includeProperty,
Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql,
ISessionImplementor session) +2182
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object
id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection,
Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor
session) +512
NHibernate.Impl.ScheduledUpdate.Execute() +559
NHibernate.Impl.SessionImpl.Execute(IExecutable executable) +206
NHibernate.Impl.SessionImpl.ExecuteAll(IList list) +135
NHibernate.Impl.SessionImpl.Execute() +292
NHibernate.Impl.SessionImpl.Flush() +130
Castle.ActiveRecord.Framework.Scopes.AbstractScope.PerformDisposal
(ICollection`1 sessions, Boolean flush, Boolean close) +115
Castle.ActiveRecord.SessionScope.PerformDisposal(ICollection`1
sessions) +103
Castle.ActiveRecord.Framework.Scopes.AbstractScope.Dispose() +76
Castle.ActiveRecord.Framework.SessionScopeWebModule.OnEndRequest
(Object sender, EventArgs e) +126

System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute
() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously) +75

Mauricio Scheffer

unread,
Nov 4, 2009, 2:37:56 PM11/4/09
to Castle Project Users
The NHibernate session is probably dirty so it's flushing. Either you
modified an entity or there's a mismatch in your mapping.

See:

http://stackoverflow.com/questions/780755/nhibernate-flush-how-it-works
http://stackoverflow.com/questions/43320/nhibernate-isession-flush-where-and-when-to-use-it-and-why

If you want to ensure that the entity is never inserted or updated set
mutable=false:
http://www.castleproject.org/activerecord/documentation/trunk/manual/attributedocs/Generated_ActiveRecordAttribute.html#ActiveRecordAttribute_Properties

Mauricio Scheffer

unread,
Nov 4, 2009, 3:21:58 PM11/4/09
to Castle Project Users
Sorry, mutable=false prevents updates and deletes, *not* inserts

On Nov 4, 4:37 pm, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:
> The NHibernate session is probably dirty so it's flushing. Either you
> modified an entity or there's a mismatch in your mapping.
>
> See:
>
> http://stackoverflow.com/questions/780755/nhibernate-flush-how-it-workshttp://stackoverflow.com/questions/43320/nhibernate-isession-flush-wh...
>
> If you want to ensure that the entity is never inserted or updated set
> mutable=false:http://www.castleproject.org/activerecord/documentation/trunk/manual/...

jake

unread,
Nov 5, 2009, 12:59:59 PM11/5/09
to Castle Project Users
Thanks, that worked.

On Nov 4, 12:21 pm, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:
> Sorry, mutable=false prevents updates and deletes, *not* inserts
>
> On Nov 4, 4:37 pm, Mauricio Scheffer <mauricioschef...@gmail.com>
> wrote:
>
>
>
> > The NHibernate session is probably dirty so it's flushing. Either you
> > modified an entity or there's a mismatch in your mapping.
>
> > See:
>
> >http://stackoverflow.com/questions/780755/nhibernate-flush-how-it-wor......
Reply all
Reply to author
Forward
0 new messages