|
Sponsored Links
Resources
.NET Research Library
Get .NET related white papers, case studies and webcasts
|
News
News
News
|
Messages: 36
Messages: 36
Messages: 36
Printer friendly
Printer friendly
Printer friendly
Post reply
Post reply
Post reply
XML
XML
XML
|
 |
Introducing NHibernate
In this latest installment, Justin Gehtland discusses NHibernate, the .NET port of the open-source Java Hibernate object/relational mapping library developed by Gavin King (now of JBoss). Read about how to use NHibernate to avoid clumsy relational queries that clutter your code.
Next month, look for Justin's follow-up article, in which he'll discuss using parameterized queries using HQL, caching, and advanced collection semantics in NHibernate.
Read NHibernate
|
|
Message #133958
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Introducing NHibernate
Interesting! And I just started experimenting with Hibernate at home to see how much I liked it. I feel a need for an O/R mapping framework at my day job, and until now I haven't seen anything I liked.
I still do not like the Hibernate XML mapping format. It's not that it's XML, it's more that it's not as clear as I think it could be. Regardless, this might just be the tool I've been looking for!
Bryan
|
|
Message #133964
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Introducing NHibernate
I still do not like the Hibernate XML mapping format. It's not that it's XML, it's more that it's not as clear as I think it could be. Whoa! Why do you think it's not clear? It's generally accepted that that XML mapping format is so clean that you don't even need a GUI tool in order to edit it.
|
|
Message #133983
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Introducing NHibernate
I am so excited about this port, I can't contain myself. On my last project, I built an or/mapper from the ground up. Using, offcourse, xml medata data mapping and domain objects replete with QueryObject. This follows the pattern listed in fowler. I had great success with it. However, when you start dealing with many-many and one-many relationships, your codes starts to get hairy. It is still doable, however, having an out of the box framework for doing so is ideal. I am actually testing nhibernate now for my current project.
-M
|
|
Message #133988
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Introducing NHibernate
I still do not like the Hibernate XML mapping format. It's not that it's XML, it's more that it's not as clear as I think it could be. Hibernate XML mapping format is the clearest I have come across, what would you change ?
|
|
Message #134010
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
1:1 M:1 lazy loading?
Does it allow lazy-loading of 1:1 and M:1 relationships? For example UniversityClass - Professor (Professor member is lazy-loaded) if I use the example in the article?
|
|
Message #134047
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
What are its features status compare to Hbernate
What fetures are supported by NHibernate compare to original Hibernate? has anybody used NHibernate in production environment?
|
|
Message #134061
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Introducing NHibernate
I think this was a great idea. Since there are fewer competitors on the .Net side it will probably be an even greater success.
|
|
Message #134400
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Are public properties really needed?
Nice article, which was very useful, but one thing is not correct:
"Of course, youll need to expose these data fields through public properties, not only for use by your other classes but by NHibernate as well. NHibernate uses reflection to access the properties of your persistent classes, and just like any other .NET library, it cant access private fields of your classes."
As far as I know, you can access private fields using reflection. I've tried another persistence framework (Gentle.Net) that supports this, but I am not sure if NHibernate does.
|
|
Message #134478
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
That was an error
That paragraph was all messed up. There are some corrections being posted to the article today or tomorrow (as soon as editing gets through with them) and this is one of them. Thanks for catching it, though!
|
|
Message #134516
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Introducing NHibernate
I still do not like the Hibernate XML mapping format. It's not that it's XML, it's more that it's not as clear as I think it could be. Hibernate XML mapping format is the clearest I have come across, what would you change ? I tend to agree with first comment that XML Mapping format is not very clear. One e.g. <class name="nhRegistration.Department, nhRegistration" table="department">
</class> Here the attribute, 'name' has 2 meanings, which is ambiguous. First is fully qualified name and second for assembly name. At the first glance of this, it is not clear purpose of 2 values for name attribute and use of it. One need to remember that first is qualified name and second for assembly. This can be easily represented as <class fullyQualifiedName="nhRegistration.Department" assemblyName="nhRegistration" table="department"> </class> Above schema does not keep any room for ambiguity. Like this there could be more e.g. for Config schema My 2 cents... Thx, Surendra
|
|
Message #134567
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Introducing NHibernate
I tend to agree with first comment that XML Mapping format is not very clear.One e.g.<class name="nhRegistration.Department, nhRegistration" table="department"></class>Here the attribute, 'name' has 2 meanings, which is ambiguous. First is fully qualified name and second for assembly name. At the first glance of this, it is not clear purpose of 2 values for name attribute and use of it. One need to remember that first is qualified name and second for assembly. The pattern being used by NHibernate for identifying class types is exactly how .NET does, so I don't see any problems. For details see Type.GetType(sting).
Pat
|
|
Message #134625
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Not 100% sold
I have used hibernate on two smaller java projects, and was on the whole happy.
However, my next project is .NET and a larger scale project. I dont know if I am happy to use Hibernate for this. It seems to me that with these object mapping frameworks you need to execute some kind of sql, or messing about with some kind of exceptional situation and once you are using the framework its awkward to get round it without making your code more awkward to read.
Only my experience though :)
|
|
Message #135035
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Check your exception handling
Interesting article and technology indeed.
I just want to comment on the try-catch handling in the sample code. ISession session; ITransaction tx;
try { session = factory.OpenSession(); tx = session.BeginTransaction(); // do database work tx.Commit(); session.Close(); } catch (Exception ex) { tx.Rollback(); session.Close(); // further exception handling }
I cant claim to know the inner workings of OpenSession but if theres a chance it throws and surfaces an exception, the catch is going to access a null reference, tx. General advice:
Acquire Resource; Try Do Something with Resource Catch Do something Finally Release Resource
Actually theres a semantic implication of OpenSession. To me it should either return a valid ISession reference to an open reference or it should throw an exception. The same goes for BeginTransaction. So, IMHO this is how to write it (my 2c):
ISession session = factory.OpenSession(); try { ITransaction tx = session.BeginTransaction(); try { // do db work tx.Commit(); } catch { tx.Rollback(); } } finally { session.Close(); }
Both session in finally and tx in catch will be valid references provided that OpenSession and BeginTransaction returns what they atomically should return, i.e. an open session in the former case and a started transaction in the latter case.
(How the other sample, the one with session and tx declared in the try branch, compiles is a mystery. tx and session is out of scope in the catch branch. But that is beside the point.)
Best regards, all in good will, Ingo
|
|
Message #135688
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: Int32 cannot be used as Identity Key?
You may use int32 for your identity key, could you send your problematic hbm file and class file to szokelizer@freemail.hu ?
|
|
Message #135689
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: Introducing NHibernate
Just to clarify it: FQN has the following format (from MSDN):
" All compilers that support the common language runtime will emit the simple name of a nested class, and reflection constructs a mangled name when queried, in accordance with the following conventions.
Delimiter Meaning Backslash (\) Escape character. Comma (,) Precedes the Assembly name. Plus sign (+) Precedes a nested class. Period (.) Denotes namespace identifiers.
For example, the fully qualified name for a class might look like this:
TopNamespace.SubNameSpace.ContainingClass+NestedClass,MyAssembly
If the namespace were TopNamespace.Sub+Namespace, then the string would have to precede the plus sign (+) with an escape character (\) to prevent it from being interpreted as a nesting separator. Reflection emits this string as follows:
TopNamespace.Sub\+Namespace.ContainingClass+NestedClass,MyAssembly
A "++" becomes "\+\+", and a "\" becomes "\\".
This qualified name can be persisted and later used to load the Type. To search for and load a Type, use GetType either with the type name only or with the assembly qualified type name. GetType with the type name only will look for the Type in the caller's assembly and then in the System assembly. GetType with the assembly qualified type name will look for the Type in any assembly.
Type names may include trailing characters that denote additional information about the type, such as whether the type is a reference type, a pointer type or an array type. To retrieve the type name without these trailing characters, use t.GetElementType().ToString(), where t is the type.
Spaces are relevant in all type name components except the assembly name. In the assembly name, spaces before the ',' separator are relevant, but spaces after the ',' separator are ignored. "
|
|
Message #135703
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: What are its features status compare to Hbernate
It's in a status, when it can be used. I use it in production environment, currently having ~100 tables, ~200 classes and ~2500 properties with many components, joined components, subclasses, joined subclasses, 1:1, 1:N, N:M connections, etc...
|
|
Message #136650
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: Int32 cannot be used as Identity Key?
I'm having the same issue. Did you ever get a response or solution? I'd be very interested. Thanks.
|
|
Message #136955
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: Int32 cannot be used as Identity Key?
You may use int32 for your identity key, could you send your problematic hbm file and class file to szokelizer@freemail.hu ?
|
|
Message #141504
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Next Article
When can we expect the next article to come out? I noticed that references were made to next month, but that was about two months ago. Thanks.
|
|
Message #141692
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
I heavily second this!
I (along with several others I know about) have implemented NHibernate successfully, and (along with the development of a very flexible Persistence layer to ensure that I can switch amongst providers at any given time) am using it in production. However, although I have a couple of books on Hibernate specifically, I've informally limited myself to using the most basic (and likely stable) subset of NHibernate's functionality. My reasoning is that while I have higher hopes for NHibernate than any other .NET solution except, eventually, ObjectSpaces -- based mostly on just how far ahead Hibernate is compared to most other options -- I personally don't have the time to test what limitations it has.
I'm finding that even with limiting myself to traditional data access patterns, the sheer amount of time saved and the sheer elegance that being able to have, for instance, a set of mappings based on interfaces and their implementers (the idea seemed backwards to me as well from a maintenance standpoint, but I set aside a portion of my object hierarchy to test the idea on and with the creation of a few memento objects I've been able to come up with some nice reductions in mapping complexity).
However, I don't have time right now to look at different methods of using the Session object and lazy loading (for instance, in a web-app) and deal with potential bugs at the fringe of the project.
The library is just enormous, and more and more work is being done on it all the time, so I am pretty sure that you'd have a huge audience for the article. Please let us know what the status is! I am very interested in some expert notions, so I can have an idea what general level of sophistry NHibernate can support without discovering for myself that I've overstepped the bounds of stability.
|
|
Message #142183
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
I heavily second this!
We are currently approaching to a version 0.4.0.0, which will hopefully will contain stable proxy support (now only collection lazy load is supported) - currently this is nearly the only feature that is missing. Other parts of the framework can be designated as highly usable, but of course performance bottlenecks, feature requests from other nhibernate versions, etc, are highly welcomed.
|
|
Message #149445
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
I heavily second this!
you indiciated that your are moving to 0.4.0. i downloaded 0.5.0 and tried to set up the database and stuff from this article (nhibernate). i keep getting this error message
"NHibernate.ADOException: problem in find ---> NHibernate.PropertyAccessException: Exception occurred setter of College.CDepartment.Courses ---> System.ArgumentException: Object type cannot be converted to target type.\r\n at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess)\r\n at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess)\r\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)\r\n at System.Reflection.MethodInfo.Invoke(Object obj, Object[] parameters)\r\n at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)\r\n at NHi bernate.Property.BasicSetter.Set(Object target, Object value)\r\n --- End of inner exception stack trace ---\r\n at NHibernate.Property.BasicSetter.Set(Object target, Object value)\r\n at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values)\r\n at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)\r\n at NHibernate.Loader.Loader.DoFind(ISessionImplementor session, QueryParameters parameters, Object optionalObject, Object optionalID, PersistentCollection optionalCollection, Object optionalCollectionOwner, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.Find(ISessionImplementor session, QueryParameters parameters, Boolean returnProxies)\r\n at NHibernate.Loader.CriteriaLoader.List(ISessionImplementor session)\r\n at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)\r\n --- End of inner exception stack trace ---\r\n at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)\r\n at NHibernate.Impl.CriteriaImpl.List()\r\n at College.f Main.mnuDepartmentOpen_Click(Object sender, EventArgs e) in c:\\csnetprojects\\college\\fmain.cs:line 262"
i renamed univiersityclass to course
|
|
Message #150128
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
What Assembly to use?
Hmm interesting. But I want to try it.
You say reference the assembly in your project. Which ones? Commons.dll (probably) DotNetMock.Core.dll (probably not) DotNetMock.dll (probably not) DotNetMock.Framework.dll (probably not) HashCodeProvider.dll (probably) Iesi.Collections.dll (probably) log4net.dll (probably not) NAnt.Core.dll (probably not) NHibernate.ddl (probably) NHibernate.DomainModel.dll (probably) NHibernate.Examples.dll (probably not) NHibernate.Task.dll (probably) NHibernate.Test.dll (probably not) nunit.framework.dll (probably not) NVelocity.dll (probably not)
Does anyone know? I couldn't find any documentation about that. I don't think that referencing all assemblies is a good thing when we are only going to use a few.
Regards,
Mark Monster
|
|
Message #153944
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Int32 cannot be used as Identity Key?
Hi I'm just starting NHibernate and c#, just wonder if you could share your sourcecode for this example
Cheers Tien
|
|
Message #158982
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
I heavily second this!
I've had the same problem: "Object type cannot be converted to target type".
The "Object type cannot be converted to target type" error is caused by the fact that the C# classes in the sample use the IDictionary interface and the...hbm.xml mapping files from the sample use the "<set.....> tag. The "<set>" tag will result in the use of a nhibernate.collections.set class. This nhibernate.collections.set class implements (via iesi.collections) the ICollection interface. NOT the IDictionary interface.
So changing IDictionary into ICollection did(in my case)help me get rid of the problem. But: it gave some other problems like not being able to read the data from the collection. Haven't had time to look into that. (Probably the IDictionary has to go back in the C# classes and the "<set>" tag from the hbm.xml file has to replaced by ..??)
Hope it helps.
you indiciated that your are moving to 0.4.0. i downloaded 0.5.0 and tried to set up the database and stuff from this article (nhibernate). i keep getting this error message"NHibernate.ADOException: problem in find ---> NHibernate.PropertyAccessException: Exception occurred setter of College.CDepartment.Courses ---> System.ArgumentException: Object type cannot be converted to target type. at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess) at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Reflection.MethodInfo.Invoke(Object obj, Object[] parameters) at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) at NHibernate.Property.BasicSetter.Set(Object target, Object value) --- End of inner exception stack trace --- at NHibernate.Property.BasicSetter.Set(Object target, Object value) at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values) at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj) at NHibernate.Loader.Loader.DoFind(ISessionImplementor session, QueryParameters parameters, Object optionalObject, Object optionalID, PersistentCollection optionalCollection, Object optionalCollectionOwner, Boolean returnProxies) at NHibernate.Loader.Loader.Find(ISessionImplementor session, QueryParameters parameters, Boolean returnProxies) at NHibernate.Loader.CriteriaLoader.List(ISessionImplementor session) at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria) --- End of inner exception stack trace --- at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria) at NHibernate.Impl.CriteriaImpl.List() at College.fMain.mnuDepartmentOpen_Click(Object sender, EventArgs e) in c:\csnetprojects\college\fmain.cs:line 262"i renamed univiersityclass to course
|
|
Message #160753
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Introducing NHibernate
Hai , As i am new to Nhibernate, can any of u guys help me in displaying the data from the table to a web page using Nhibernate
else i will put in this way
how can i do the operation like modifying,deleting,selecting the records from the database using Nhibernate
please kindly help me regarding this
rgds Kiran
|
|
Message #172239
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Error: could not load object
When I attempt to load UniversityClass Data, I encounters a error.it is: could not load object The code is as follows: try { UniversityClass relateClass = (UniversityClass)aEntityRule.GetEntity(typeof(UniversityClass),3); Response.Write(relateClass.Students.Count.ToString()); } catch(Exception mme) { Response.Write(mme.Message); } Who can tell me why?
|
|
Message #172245
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Could provde the sourceCode, especially the *.hbm.xml
Hi, Justin Gehtland : I use NHibernate only for 2 weeks, and I found it is really a very good one. In my experience of using NHibernate, I use the one-to-many or many-to-many relationship between classes. Just as the release notes say, the relationship can load the date automatically, but I encounter a error at the "save" function called. The error in stack is : at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything).
The sample code: Department aDepartment = new Department(); aDepartment.deptname = "Computer Science";
aEntityRule.Save(aDepartment);
|
|
Message #217580
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
How to Have Multiple XML Mapping for Same Class?
I have multiple database tables which I want to map in multiple XML files to the same Business Object.
Is this possible?
For example, I have a class which is a kind of 'NameValueCollection'. I also have a number of tables where I want to populate a collection of NameValueCollection instances with the ID and Display from various columns in these tables.
Thanks, Damon
|
|
 |
| |
|
New content on TheServerSide.NETNew content on TheServerSide.NETNew content on TheServerSide.NET |
 |
 |
Language "mashups" will become more prominent, and developers will become polyglots, one programmer suggests.
SearchWinDevelopment.com offers an introduction to the language, performance, testing and data management improvements in VS 2008.
VBCode.com code snippets cover all aspects of application development, from data binding to security to the user interface.
Get up to date on XAML best practices with a variety of articles, tutorials and webcasts. [SearchWinDevelopment.com]
One team's experience with the VSTS DB edition suggests that it can improve workflow for dev teams. It also enhanced Agile efforts.
(June 24, Article)
Microsoft has begun to include DSL tools in the VSTS kit. A new book by Steve Cook and other VSTS team members helps set the stage.
(June 24, Article)
Cartoon: Be it ever so humble there is no place like your home after you get a Microsoft Home Server .
(June 18, Cartoon)
Microsoft's Thom Robbins says new technology to highlight in NET 3.5 includes AJAX, LINQ for both C# and VB, as well as tooling enhancements intended to ease the task of building WPF, WF and WCF apps.
(June 29, Podcast)
Venkat Subramaniam discusses AJAX bottlenecks, the tenets of Agile development and more. He spoke at the Ajax Experience.
(June 25, Tech Talk)
In the second of a two-part series, Michele Leroux Bustamente discusses design decisions related to the claims-based security model. Read the story and walk through the process for creating a set of claims-based utilities to encapsulate claims authorization at the service tier.
(May 24, Article)
Understanding why the Entity Framework exists and learning where it can fit into your projects can get you prepared for the eventual release early next year.
(May 10, Article)
Resource: This learning guide gives you quick access to useful links on Windows Communication Foundation security information.
(April 24, Article)
TSS.NET's Jack Vaughan spoke recently spoke with Microsoft's Brad Abrams to find out what he is seeing in the field and what the chefs in Redmond are cooking. Along the way he discusses patterns of AJAX frameworks.
(April 11, Article)
In a two-part series, Michele Leroux Bustamente explains how claims-based security is supported by WCF, and how you can implement a claims-based security model for your services.
(March 29, Article)
Windows Workflow Foundation is a new technology that many developers will need to get their heads around. In a brief excerpt adapted from Programming Windows Workflow Foundation: Practical WF Techniques and Examples using XAML and C#, K.Scott Allen considers aspects of workflow definition.
(March 22, Chapter Excerpt)
|
|