Thursday, June 14, 2007
Preview 3 has this functionality, but there are a few things to mention.

ActiveWriter use ActiveRecord assembly to generate NHibernate config files. So you'll need Castle.ActiveRecord.dll, NHibernate.dll and all necessary dependincies to make it work.



  1. Set the target to NHibernate
    This way, AW will generate .hbm.xml files for each entity in your model.
  2. Set the Assembly Path to where Castle.ActiveRecord.dll, NHibernate.dll and all necessary dependincies reside.
    The design decision was that, I didn't want to package these assemblies with AW. Rather than that, I thought user will most probably have them so they can choose whatever version they want to generate the configuration. If you don't supply the path, AW (VS, actually) will look for them in GAc and then {Your VS Path}\Common7\IDE\Castle.ActiveRecord.dll, so if you have them in one of those places, it should be fine.

    One other quirk is, if you first try to generate with the wrong path, setti ng the correct one later won't work until you restart Visual Studio. This is the framework's limitation, once you try to load an assembly and get an error, the result will be cached for subsequent tries. So VS appdomain should be restarted to make it work. I'll have a possible soliton for this for a future version of ActiveWriter (will try to load in a dummy appdomain, then in the VS appdomain)

    You may use the fully qualified assembly names for Active Record Assembly Name and NHibernate Assembly Name to target a specific version in the GAC, if you have more than one in there.
  3. When you save the model, AW will generate configuration.
I'll prepare a better documentation in the wiki.

Have fun.

Update:

AW does not work with release version of Castle assemblies (RC2?) for NHibernate generation, it works with the trunk (or with recently compiled assemblies). You can use the latest bits from the build server: http://builds.castleproject.org/cruise/index.castle
6/15/2007 12:12:58 AM UTC
I'm trying to use ActiveWriter preview 3 but I get an error message when I try to save my model. I downloaded Caste .Net 2.0 which includes NHibernate assemblies. I get the error even when I try to save an empty model.
Please can you tell me what causes this error.

The error is:
Error 1 Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.
at Altinoren.ActiveWriter.CodeGeneration.CodeGenerationHelper.Generate()
at Microsoft.VisualStudio.TextTemplatingE8FEC580F71E6AB4604F604261EBEA57.GeneratedTextTransformation.TransformText() in c:\work\twc.net\twc\twc.model\twc\model\TWC.actiw:line 32 C:\work\twc.net\twc\twc.model\twc\model\TWC.actiw 1 1

6/15/2007 1:01:02 PM UTC
Daniel,

I believe you're using the release version of Castle assemblies (RC2?). AW does not work with them for NHibernate generation, it works with the trunk (or with recently compiled assemblies).

Can you use the latest bits from the build server? They might break some code if you have other piece of classes but it includes NHibernate 1.2 and castle assemblies are mostly good from the trunk.
http://builds.castleproject.org/cruise/index.castle
Gokhan
6/15/2007 10:55:53 PM UTC
Thank you for your reply!

I updated CastleProject and it NHibernate generation seems to work if I build a simple model from scratch.
But when I drag my tables from the Server Explorer the automatically generated model causes an error when I try to save it. My database schema consists of aprox 15 enities with many-to-one(also self reference) and many-to-many relationships. Please let me know why I get this error.
Thanks again!

Daniel

Error 1 Running transformation: System.ComponentModel.Design.ExceptionCollection: Exception of type 'System.ComponentModel.Design.ExceptionCollection' was thrown.
at Altinoren.ActiveWriter.CodeGeneration.CodeGenerationHelper.GenerateARAssembly(CodeCompileUnit compileUnit)
at Altinoren.ActiveWriter.CodeGeneration.CodeGenerationHelper.Generate()
at Microsoft.VisualStudio.TextTemplating660432FCBF77F3364C228DCC59B7A328.GeneratedTextTransformation.TransformText() in c:\work\twc.net\twc.model\twc\model\TWC.actiw:line 32 C:\work\twc.net\twc.model\twc\model\TWC.actiw 1 1
6/18/2007 7:58:39 AM UTC
@Daniel,

The error means that your outputted code cannot be compiled. It may miss a project reference or a name clash etc.
First, try targeting ActiveRecord rather than NHibernate and make it build. Than turn your AW target to NHibernate and try again.
Gokhan
6/18/2007 8:25:03 AM UTC
I'm trying build 424 now, but still no luck, maybe it is VisualSVN that gives me problems:

Error 1 Running transformation: System.EntryPointNotFoundException: Entry point was not found.
at VisualSVN.VS.Interop.NativeExtenderCallback.GetPathStatus(String path, IntPtr project)
at VisualSVN.VS.Interop.NativeExtender.FireGetItemStatus(NativeExtender* , IVsHierarchy* This, UInt16* path)
at EnvDTE.ProjectItems.AddFromFile(String FileName)
at Altinoren.ActiveWriter.CodeGeneration.CodeGenerationHelper.Generate()
at Microsoft.VisualStudio.TextTemplating97080AAF525AAA6B892FC5EDAE5D784F.GeneratedTextTransformation.TransformText() in c:\utv\Model.actiw:line 32 C:\utv\Model.actiw 1 1

AsbjornM
6/18/2007 9:06:40 AM UTC
@AsbjornM,

The error seems to get thrown where AW adds the generated hbm.xml file to the project. The error looks like a wrong assembly is loaded dynamically, where a method cannot be found.

AW does load assemblies on the fly for NHibernate generation, but it's way before EnvDTE.ProjectItems.AddFromFile call. If you reach to that point, dynamic assemblies are already loaded successfully.

Can you use the same file without the source control in place to see if code generation works in that case?
Gokhan
6/18/2007 11:04:39 AM UTC
I uninstalled VisualSVN, and no problems :)
But, I got another problem, I'm probably going the wrong path, but I want to use this:
http://ayende.com/Blog/archive/2007/06/03/NHibernate-Query-Generator-1.9-is-out.aspx

And I think that I need to set the mode to Nhibernate as above to generate the *hbm.xml files, and they do now.
But I cannot compile, because I get this:
"The type or namespace name 'ActiveRecordBase' could not be found (are you missing a using directive or an assembly reference?)"

And when I look at the generated source I see this:
public partial class MyEntity : ActiveRecordBase<MyEntity> {
But no using castle.activerecord is added to the sourcefile, what I'm doing wrong?


AsbjornM
6/18/2007 11:36:58 AM UTC
@AsbjornM

Hmm. This might be an AW bug, depends on how you look at it.
First, when the target is NHibernate, AW strips all AR stuff from the generated code, so ActiveRecordBase as the base class might get stripped, this is configurable so I may not mark this as a bug, I'll consider it.

Workarounds:
- If you don't want ActiveRecordBase as the base class, set Use Base Class on the model to false.
- If you want it, add Castle.ActiveRecord to Additional Imports list (when the target is NHibernate. This is automatic otherwise)
Gokhan
6/18/2007 11:38:19 AM UTC
By the way, AFAIK, HQG can work on AR classes but I might be wrong.
Gokhan
6/18/2007 12:02:28 PM UTC
I thought that NHQG needs the *.hbm.xml files, and to get AW to generate them I needed to change the config in AW.
But if/when I manage to generate the files from NHQG then those needs the classes to inherit from ActiveRecordBase...
If I put something into the "Additional Imports" I cannot get that to work..

Once I got the query files generated but now I cannot get anything again.. which version did you test this against?, I'm using build 424, but can use anything if things just can match a little..
AsbjornM
6/18/2007 12:54:29 PM UTC
Just tested it against Ayende's official 1.9 download. Results:

- It does work on AR assemblies, no need to feed it with hbm config.
- It doesn't care what the base class is. Works with or without it set.
- To use Additional Imports in AW, in additional imports dialog, just add a new one and change the name property to Castle.ActiveRecord .
Gokhan
6/18/2007 1:14:05 PM UTC
Ok, then I'm obviously doing something wrong, the NHQG only gives me an QueryBuilder.cs, not the aditional files.. I got them only once..

AsbjornM
6/18/2007 1:26:32 PM UTC
> Ok, then I'm obviously doing something wrong, the NHQG only gives me an QueryBuilder.cs, not the aditional files.. I got them only once..

When the target is ActiveRecord? As you know, if the target is NHibernate, NHQG won't be able to infer AR classes from your assembly, since there won't be any.
Gokhan
6/21/2007 1:33:15 PM UTC
When using ActiveWriter to generate NH files it is adding the AR attributes to my classes?

I have my own base class:
ie.

DomainObject T, K (brackets removed - sees it as html) - is it possible to define something like this?

---

It would be incredible if you were able to take this one step further and define a IRepository/IDao model :)
6/21/2007 1:42:11 PM UTC
@Steve,

AW should strip all AR attributes when targeting NH. Please let me know if it doesn't.

You can use your own base class (see model properties), but I believe it doesn't support generics. Can you open a jira issue on support.castleproject.org for this?
Gokhan
7/4/2007 1:19:29 PM UTC
i've had great success with activewriter. the only limitation i have found, is that the .hbm.xml files don't contain the explicit assembly and namespace which results in not found types at runtime.

i wrote a small executable that pokes in the hbm.xml and inserts the namespace and assembly information prior to compilation using a pre-build batch.

i also do a copy of the .hbm.xml to ayende's query generator and copy the files back into the project pre-build.

this ensures that i have - uptodate hbm.xml that match my domain, up to date class and query classes for the domain model, and only make changes via active writer.
7/6/2007 7:09:59 PM UTC
Is a bug in activewriter for nhibernate if don't add the explicit assembly or namespace in the hbm.xml file?
How can I add hbm.xml files to nhibernate configuration without that propertys?
TIA
7/18/2007 11:52:23 AM UTC
@David, @Rodrigo

Yes, lack of assembly name is a bug. Fixed in the trunk now.

Sorry for the trouble.
Gokhan
7/30/2007 3:18:39 PM UTC
Hi
Two problems I have with AW ...

First, I can't see the template for new AW diagrams, after installing AW. I'm using Visual Studio Spanish Version. There are any known problems with that?

Seconds, I don't know why, but is very difficult add relations to diagrams. When I try to make drag and drop between classes with any type of relationship selected the first class clicked move. Sometimes, pressing CTRL I can see the black square in the relation icon, and I can drag correctly, but sometimes I can't

There is any forum for this type of comments?

TIA

Rodrigo Juarez
8/1/2007 5:28:00 AM UTC
Is there any chance that the trunk code will be available as a binary download for preview 4?

I appreciate you must be busy at the moment...
8/6/2007 1:32:52 PM UTC
What is the best way to achieve many-to-many mapping with additional properties.

IE: School has many classes. Classes have many students. Students have many classes. The many-many relationship has a "grade" property for each student in each class?

Is there a way to easily manage this in NHibernate and .... is there a way to represent this in active writer - is this on the roadmap? Will it essentially be editable properties for the many-many line?

Sorry for all the q's - any assistance is appreciated...
8/6/2007 2:23:06 PM UTC
@David,

The best way is to have an additional entity for StudentClass table (the table in between, where you define m2m) to access it's properties.

See:
http://forum.castleproject.org/viewtopic.php?t=151&highlight=manytomany
Gokhan
8/15/2007 4:15:32 AM UTC
For the life of me I couldn't get any of my MySql tables to drag drop to the designer... no error, no nothing...

Figured out that it was that I have mysql connector/net 5.1.2 The ActiveWriter project references an an earlier version...

What I did was go rename the one installed by ActiveWriter in C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies and copied the newer one from the MySql connector/net installation into the folder. Fixed me right up!
8/15/2007 6:41:10 AM UTC
@Shane,

I just realized that yesterday, in replaying to a similar problem in the Castle Dev list.

The problem is, I have to have a reference in the design time to make it compile. If the installed connector version is different, runtime casting chokes since it sees one in VS privateassemblies folder and one in GAC. Favors the one from the folder since it's the one compiled against, but the connection object coming from the Server Explorer is from the one in the GAC.

I don't have an immediate solution other than the one you did. But I'll sort this out out of the box, it's just pain.

Thanks a lot for the info.

Gokhan
Gokhan
8/15/2007 2:38:29 PM UTC
Yep, that's how I found it was the reference. (downloaded svn trunk) I removed reference to MySql.data and added back the one in the installed directory... Worked perfectly...

Now, there's a problem with that solution. ActiveWriter would be dependent on MySql connector/net even if mysql wasn't to be used! That's bad.

Maybe there's a solution by testing for the assembly, then if there, include it using reflection or something at runtime? Maybe a Plugin type architecture for different database helpers?

Don't have a lot of time to play with it right now on my own though. The stopgap is good enough for now.
8/18/2007 11:03:42 AM UTC
@Shane,

Fixed in the trunk. Moved to IDbConnection for all metadata retrieval jobs.

AW no longer packed with MySQL.Data.dll, and no compile time references :)

I'll release Preview 3.1 shortly to address this issue and a show stopper bug in hbm.xml generation.
Gokhan
5/19/2008 12:39:34 PM UTC
Cool, the post.

Thanks for the information.
10/16/2008 12:07:16 PM UTC
Thanks for the information
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):