Hi,
Just wondering if anyone has done any work on CLSO code generation using NHibernate for the persisting the business objects. Just done some reading on both CSLA and NHibernate and it seems like a really good combination especially with the properties option in NHibernate.Contrib.
Yes, CSLA and NHibernate is a combination we are using. We are doing some code generation for our BO classes as well using our own in-house CodeSmith templates to fit in with our framework.
I know other people on this forum use different code generation tools as well.
If you've got any ASP.NET experience, then writing CodeSmith templates will seem quite straightforward.
Hi
Thanks for the response.
I hope I dont upset the CLSA experts by continuing the theme of NHibernate on this forum but my justification is that I am trying to integrate NHibernate into CSLA and appreciate the help of people like yourself who have trodden the same path. It it offends then I am most happy to continue off line.
I have been some playing with NHibernate and CSLA. I have my business object working but am now trying to add the NHibernate to the Data Portal code and have a few further questions which I was hoping you could answer. I tried to use the Attributes Contrib in my business objects, but with not a lot of success.
The first problem is that the examples in the NHibernate doc dont really give a good example of how to decorate the class and associated properties. Do you have an example Business Object class that you would be prepared to share with others on this forum. It complains that my attribute properties are not correct.
The second issue was that when I tried to run cfg.configure() it complains about a missing config file. I guess that uisng the Attribute appriach and the use of reflection to stream the class info into the config I no longer need to make this call or is there another reason why this line was left in the example in the Contrib section of the user manuel.
TIA for any help
Steven,
Have a look at this code fragment on another thread. That may help you identify the kind of code you should be aiming for inside your Data Portal code.
As for the NHibernate documentation, it is poor compared to the Hibernate documentation. I actually prefer the Hibernate documentation and use that more often.
Use the NHibernate test code and examples, they do have some good stuff in there.
Here's an example of some fields marked up with NHMA attributes:
[Id(0, Name = "RoomId", Column = "room_id")]
[Generator(1, Class = "assigned")]
private int _roomId = 0;
[Property(Name = "RoomName", Column = "room_name")]
private string _roomName = String.Empty;
[Property(Name = "AreaId", Column = "area_id")]
private NullableInt32 _areaId = null;
[Property(Name = "RoomLength", Column = "room_length")]
private NullableDecimal _roomLength = null;
Notice that we're using NHibernate.Nullables here as well.
As for the missing config file, we've set our solution up to use a named configuration file, which can be different for different DBs. So in our singleton NHibernate factory "manager" class we have the following:
Configuration cfg = new Configuration();
cfg.Configure(factoryCfg);
cfg.AddInputStream(stream); // Use the stream here
stream.Close();
where factoryCfg is the name of the physical configuration file (e.g. Nfs.hibernate.cfg.xml) that we want to use to configure this particular instance of a factory. This allows us the flexibility of having different factory configurations via different NHibernate configuration files.
What I really want to do is convert the ProjectTracker example to use NHibernate and submit it to the new CodePlex site for everyone to share. I think that's the best solution going forward. I just need to find the time to do it.
I'm on holiday next week, so that will have to wait a little bit longer. So I won't be posting for a while.
HTH
DavidDilworth:What I really want to do is convert the ProjectTracker example to use NHibernate and submit it to the new CodePlex site for everyone to share. I think that's the best solution going forward. I just need to find the time to do it.
David,
We are currently evaluting the combination of CSLA and NHibernate and it would surely help to have the ProjectTracker app available in NHibernate format.
Regards,
Koen
The short answer is no.
For a fuller answer see my response on this thread.
As it happens, we've finally got round to doing an NHibernate version of Project Tracker. We're working on it right now.
So I'll post again when the code is available for public viewing.
Fingers crossed, it should be available sometime in the next week or two.
The short answer is "no". All the books I've seen are focused on Hibernate, rather than NHibernate. And to be honest, as I've mentioned before, the documentation for Hibernate is actually much better than the NHibernate version.
We've picked up lots of information from the code examples, some blogs and the forums, which are quite well supported.
So, if you're looking for a quick fix - there isn't one.
But....if you wait around just a little bit, then you might just see the ProjectTracker NHibernate example.
We've used a version of NHibernate that hasn't changed (v1.0.2) so all the documentation is in the Hibernate 2.1 documentation.
It is easier than you think it is, once you get your head into it.
DavidDilworth:
But....if you wait around just a little bit, then you might just see the ProjectTracker NHibernate example.
Ok, for those of you that are interested in NHibernate I have some good news.
We have completed an NHhibernate version of the ProjectTracker example project.
I am currently corresponding with Rocky to see if I can get it released as part of the CSLAContrib project on CodePlex.
Watch this space!
My question is not maybe related to this thread, but is there an automatic generation of tables from objects, with NHibernate? I mean, do we have to explicitly create the structure of tables? I saw that some DAL tools let the developer works with objects only, and they generate the database without an explicit mapping.
I do not know if I am clear ;) .
Yes, you can automatically generate a database schema from an NHibernate mapping file. Can I suggest that you watch episode #51 from dnrTV.
http://www.dnrtv.com/default.aspx?showID=51
Oren Eini demonstates exactly how to do this.
DavidDilworth:Yes, you can automatically generate a database schema from an NHibernate mapping file.
Thanks for the link. No easy for me, as English is not my first language, it is easier to read it than to understand it when someone spoke.
Well, I was not clear enough, in fact, it is the mapping I would like to generate automatically. I have classes, and he mapping and the database are generated. Is that possible with NHibernate?
Thank :)
Yes, I think you probably can.
We use the NHibernate.Mapping.Attributes.Dll, which allows you to markup your class with standard Attibutes that describe the mapping you want.
These attributes are reflected from the class code to build a mapping file. This is done in memory as a one-off task. Then as a debugging aid we write out the mapping file to a physical file as well. This technique is demonstrated in our ProjectTracker.NHibernate example code.
If I understand correctly, the schema generation API works off a mapping file. So I guess if you have a mapping file either in memory or on disk, then you might be able to use that to create the schema.
You'll need to go digging into the NHibernate API documentation for some help on that part though - not my area of expertise I'm afraid.
I can (at last) announce that there is now a ProjectTracker.NHibernate example solution on the CSLAcontrib site on CodePlex.
Can I suggest that all future CSLA / NHibernate questions (especially those related to the ProjectTracker.NHibernate solution) are posted on the CslaContrib forum.
Thank you all for your patience and support.
Hey, it's not good ... it's a great news! I'm so excited to see is.
Tnx David
Copyright (c) Marimer LLC