Ramblings from the Creator of WilsonDotNet.com
Thanks for the example, i will check it out.
btw. what a links, trying to get google to like you? :-)
Martijn's Cuyahoga is probably the only other real example I've seen, but to me it was too much of a real app and not enough of an example -- not any fault of his, afterall that's the point since it is a real app that he's making with it.
As for refactoring into different layers -- I don't think its a challenge at all actually. Its mostly the same principles you would apply in any other layerd app, although easier in my opinion, but of course I left that undone in my example.
I was able to make NHibernate work against access using the oledb option.
Thanks for the example app - I've been looking for something like this for a couple of weeks now. This one looks like it demonstrates a lot of the main features I would like to take advantage of.
However, I'm having trouble getting the example app to run. In the LoadContacts() method, when I hit this line:
this.ContactGrid.DataSource = session.CreateQuery(query).List();
I get this error:
An unhandled exception of type 'NHibernate.ADOException' occurred in nhibernate.dll
Additional information: Could not execute query.
Any suggestions on what I might be doing wrong?
Hopefully someone more experienced with NHibernate can shed some light on it. The only thought I have is probably not the issue, but I suppose I should ask anyhow -- have you created the database with the sql script? Yea, probably not the issue. :)
Good luck, Paul
Yeah, I ran the script to create the db instead of doing it by hand. I haven't been able to get ISession.CreateQuery() to work in either your example or my practice app. Still can't figure it out. If I come up with the solution, I'll post it here.
I figured it out. Dumb move on my part: for some reason the ORMExample login didn't work for me. I just changed it to a login that does work and voila, I'm in business!
Now if I can figure why I'm messing around with computers at midnight on a Saturday night instead of messing around with my wife, I'll be making some real progress.
There is probably something wrong with your connection string. Take a look in the log.txt file for more details about the exception.
This is one of the few examples available about NHibernate, that actually represent something out of the real world.
But there's one mayor thing I don't like about the code. It is impossible to reuse the business model in some other form of presentation layer.
That is one of THE things you need when building extendable and maintainable applications.
Its definitely not intended to be a model for best practices. I actually thought about making it a little better in that regard, but I think it would make it harder to grasp the NHibernate usage for some that aren't as experienced.
Most O/R Mappers (EntityBroker being the exception) assume that you will provide the plumbing for distributed apps, whether it be web services or remoting, just like you would in any other case -- and its not that much different, so I don't really see the problem.
If so, were you able to use the appConfig connection section "as is"?
I am experiencing connection probs :-(
If somemone can confirm that the conenction should work as is, then that'd be a help.
It should just be a simple matter of getting the connection string correct -- especially if you have a named instance for Sql 2005.
at least I know where I am going wrong.I have tried integrated security etc in the connString.Still no joy.
Could someone who is using the sample app with sql2005 email / post their nHibernate dbConn section?I apologise for this slightly off-topic :-(
Thanks for the 'real' example Paul.
Was beginning to doubt whether I'd find anything resembling a real-world scenario for nHibernate on the web.
Thanks for the nice example.
But can you tell me, from where can i get the documentation on NHibernate.
Uh, my guess would be the NHibernate site.
This is the first NHibernate (or Hibernate) example that I was able to run successfully. I ran it using VS.NET 2005 using MSDE for the database. The only change I made was to update App.config with the database instance I configured for this example (as opposed to using the default instance). The example is sufficiently rich in features to make it a good basis for further study in understanding the Hibernate configuration and programming details. Thank you very much for taking the time to post this example.
HOW CAN WE USE NHIBERNATE WITH SQLSERVER 2005....I AM HAVING A DRIVER ERROR...SECONDLY SOME TIMES I GET AN ERROR ABOUT .HBM.XML NOT FOUND....HELP
You shouldn't need to do anything differently for Sql Server 2005, other than change your connection string if that's necessary on your install. As for hbm.xml errors, I would think that you would get more help on the NHibernate forums, from regular NHibernate users, instead of asking me. I'm pleased to offer something to the NHibernate community, but keep in mind that I do have my own ORMapper that occupies my time.
Thanks for your work, it's very interesting and much more completed than other.
I would ask a question. In the example you use always session.CreateQuery so you use the IQuery interface. So you must make the query string (SQL string). In other example I have seen session.CreateCriteria. In the first you must know the DB structure and think in Relational mode (SELECT, JOIN, OUTER JOIN and so on). In the second you think in more OO. It's true? It is better use session.CreateCriteria? I'm novice in NHibernate but I think that I must masquerade the DBMS. A real application with NHibernate don't must have SQL-spagetti (also for security reason aka SQL Ingnition)
First, keep in mind that I'm not an NHibernate expert since I have my own ORMapper -- so I simply used what I did to make it work and don't claim its "best". But having said that, I actually do like to think in Relational mode and don't view that as a problem -- but I agree its nice that an OO viewpoint is also supported. I do the same thing with my ORMapper -- I tend to build Sql strings, since that's my viewpoint, but the ORMapper also supports OPath for OO thinking. For my ORMapper though I do have a QueryHelper that helps me build those Sql strings, so I don't have to hard-code table and filed names, and I can also make sure my Sql strings are "clean" to avoid Sql injection. I don't know if NHibernate has a similar thing to avoid such hard-coding and Sql injection, so while that's not a problem with my ORMapper, it may be more advisable with NHibernate to avoid it.
Thanks, Paul Wilson
man, seems in connection string shall change "User=ORMExample" to "Uid=ORMExample"
I have been searching for an example of NHibernate and was glad to find this. I'm kind of a newbie, so sorry but how do you get the database data? Thanks.
I have been looking for a good example for long time now - i found yours and it were working the first time - damn good work! :)