session.Save(new UserAudit{Page = page, User= session.Load<User>(userId)});On Thu, Oct 7, 2010 at 11:53 AM, bdaniel7 <[email protected]> wrote: > UserAudit is mapped, yes, but it has a property reference to the User > and not an int UserId. > > So I would have to do new UserAudit{Page = "", User = LoggedUser} > By the way, I'm using Castle AR for persistence. > > And I don't keep the full User in session, but a slim version, and I > load the User only when needed. > > Since this audit is supposed to be performed at each page access, I > thought it would be too much overhead to load the user each time. > Anyway, this design looks rather shady to me, but I don't know other > way. > > On Oct 6, 6:54 pm, Fabio Maulo <[email protected]> wrote: > > eh? > > and why not > > session.Save(new UserAudit{Page = page, UserId= user.Id}); > > > > The UserAudit is a mapped class, no ? > > > > > > > > On Wed, Oct 6, 2010 at 9:50 AM, bdaniel7 <[email protected]> wrote: > > > the UserAudit looks like this: > > > > > public class UserAudit > > > { > > > readonly DateTime createdOn = DateTime.Now; > > > string page; > > > User user; > > > > > public virtual string Page { get { return page; } set { page = > > > value; } } > > > public virtual DateTime CreatedOn { get { return createdOn; } } > > > public virtual User User { get { return user; } set { user = > > > value; } } > > > } > > > > > I tried also > > > > > insert into UserAudit (Page, User) select :page, u.Id from User u > > > where u.Id = :userId > > > and > > > insert into UserAudit (Page, User.Id) select :page, u.Id from User u > > > where u.Id = :userId > > > > > but I get the same exception. > > > > > On Oct 6, 3:01 pm, Fabio Maulo <[email protected]> wrote: > > > > [User] <= that is a MsSQL column name > > > > with HQL you have to use properties names > > > > > > On Tue, Oct 5, 2010 at 1:31 PM, bdaniel7 <[email protected]> wrote: > > > > > Hello, > > > > > > > I'm trying to perform an update using HQL: > > > > > > > string query = @"insert into UserAudit (Page, [User]) select :page, > > > > > u.Id from User u where u.Id = :userId"; > > > > > > > sqlQuery = session.CreateQuery( query ) > > > > > .SetParameter( "page", requestedPage ) > > > > > .SetParameter( "userId", UserId ); > > > > > sqlQuery.ExecuteUpdate(); > > > > > > > and I get this exception: > > > > > > > NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type > > > > > 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, > column > > > > > 29 [insert into UserAudit (Page, [User]) select :page, u.Id from > User > > > > > u where u.Id = :userId] > > > > > > > column 29 would be at i from insert. > > > > > > > The same query > > > > > "insert into UserAudit (Page, [User]) select 'boo', u.Id from Users > u > > > > > where u.Id = 1" > > > > > works when executed in SQL Mgmt Studio. > > > > > > > I tested with a string instead of param :page, but I get the same > > > > > exception. > > > > > > > I'm running Antlr 3.1.0 and NH 2.1.2 > > > > > > > What it's wrong with it? > > > > > > > Thanks, > > > > > Daniel > > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > Groups > > > > > "nhusers" group. > > > > > To post to this group, send email to [email protected]. > > > > > To unsubscribe from this group, send email to > > > > > [email protected]<nhusers%[email protected]> > <nhusers%[email protected]<nhusers%[email protected]> > > > > > <nhusers%[email protected]<nhusers%[email protected]> > <nhusers%[email protected]<nhusers%[email protected]> > >> > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/nhusers?hl=en. > > > > > > -- > > > > Fabio Maulo > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "nhusers" group. > > > To post to this group, send email to [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]<nhusers%[email protected]> > <nhusers%[email protected]<nhusers%[email protected]> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/nhusers?hl=en. > > > > -- > > Fabio Maulo > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- Fabio Maulo -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
