Problems with NHibernate Templates

NHibernate Forum

Problems with NHibernate Templates

Postby mdsrlz on Fri Jan 13, 2006 6:42 pm

Hi!

I'm using MyGeneration to generate code (C# and Hbm.xml) from Mysql.
The version of the data base is 3.x.

I have four templates:

- NHibernate Class Generator
- NHibernate Object Mapping
- NHibernate Object Mapping 1.1
- NHibernate OM - 0.7.1

Using any of these templates, the primary key is not mapped into the hbm.xml file.

When I try these four templates using Mysql 5.x, only the last (NHibernate OM -0.7.1) generates the mapping of the primary key.

Can you help me?

Thanks!
mdsrlz
Lurker
 
Posts: 7
Joined: Fri Jan 13, 2006 6:31 pm
Location: Blumenau / SC / Brasil

Postby mike.griffin on Sat Jan 14, 2006 6:12 am

All of the NHibernate are user submitted, look at this post:
http://www.mygenerationsoftware.com/php ... php?t=1505

Find out whose you're using and if you go to thier archive on the template library you can post a message there and it will be sent directly to the author. You might have to register on the Template Library but it's very easy.
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Re:

Postby mdsrlz on Mon Jan 16, 2006 4:25 pm

mike.griffin wrote:All of the NHibernate are user submitted, look at this post:
http://www.mygenerationsoftware.com/php ... php?t=1505

Find out whose you're using and if you go to thier archive on the template library you can post a message there and it will be sent directly to the author. You might have to register on the Template Library but it's very easy.


Hello Mike! Thanks... I've posted a message for the three authors.

Tks!
mdsrlz
Lurker
 
Posts: 7
Joined: Fri Jan 13, 2006 6:31 pm
Location: Blumenau / SC / Brasil

Postby gekannt on Mon Jan 16, 2006 4:50 pm

Are you using a composite primary key, i.e. a primary key with more than one column? The reason I ask is that the OM - 0.7.1 template has some support for composite keys, but the other three templates do not, which would explain the difference in behavior when using MySQL 5.x.. However, last I checked, the composite key support in that template was incomplete. (Disclaimer: I'm not the author of that template; my answers can't be considered authoritative.)

If that's the case, you have a few options. If you have control over the database schema, you could use a synthetic primary key instead. Or, you could write the .hbm files yourself. NHibernate does support composite primary keys, even though they're not recommended. Finally, you might look at http://www.objectmapper.com, which is another (recently) free tool that has some support for generating NHibernate mappings. It's slower and not nearly as customizeable as MyGeneration, and the class files it generates leave something to be desired in my opinion, but when I looked at it a few months ago, it was a little better than the existing MyGeneration templates at handling odd database schemas. It might do composite keys; I don't know.

If that's not the case, if you're not using a composite key, can you post the table schema and .hbm.xml file that's generated from the 1.1 template?
gekannt
Private First Class
 
Posts: 11
Joined: Tue Oct 18, 2005 11:55 am

Re:

Postby mdsrlz on Mon Jan 16, 2006 7:03 pm

gekannt wrote:Are you using a composite primary key, i.e. a primary key with more than one column?

Yes.

gekannt wrote:The reason I ask is that the OM - 0.7.1 template has some support for composite keys, but the other three templates do not, which would explain the difference in behavior when using MySQL 5.x.. However, last I checked, the composite key support in that template was incomplete. (Disclaimer: I'm not the author of that template; my answers can't be considered authoritative.)

Hum, ok. I'm talking with the author of the OM - 0.7.1.

gekannt wrote:If that's the case, you have a few options. If you have control over the database schema, you could use a synthetic primary key instead.

I'm sorry, but what is a "synthetic primary key"?

gekannt wrote:Or, you could write the .hbm files yourself. NHibernate does support composite primary keys, even though they're not recommended.

Ok, probably I'll do it.

gekannt wrote:Finally, you might look at http://www.objectmapper.com, which is another (recently) free tool that has some support for generating NHibernate mappings. It's slower and not nearly as customizeable as MyGeneration, and the class files it generates leave something to be desired in my opinion, but when I looked at it a few months ago, it was a little better than the existing MyGeneration templates at handling odd database schemas. It might do composite keys; I don't know.

Thanks, I will take a look.

gekannt wrote:If that's not the case, if you're not using a composite key, can you post the table schema and .hbm.xml file that's generated from the 1.1 template?

I have to use a composite key because the tables already are created.

Thanks! ; :P
mdsrlz
Lurker
 
Posts: 7
Joined: Fri Jan 13, 2006 6:31 pm
Location: Blumenau / SC / Brasil

Postby mike.griffin on Mon Jan 16, 2006 8:33 pm

Remember, we grow our communtiy when users submit great templates, it's easy to support composite keys, my ASP.NET page generator for dOOdads does just that. The ITable has a primary keys collection. 8)

Anyway, I hope you find a working solution.
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby gekannt on Tue Jan 17, 2006 12:01 pm

I'm sorry, but what is a \"synthetic primary key\"?

A synthetic key is a number that doesn't have any meaning in the problem domain, it's just used internally by the database. So to use a synthetic primary key, you'd add a new autoincremented integer column to your table, set that as the primary key, add a unique constraint for the columns from your old primary key, and change any foreign keys or constraints or whatever referring to your old composite key to refer to the new key.

It's a bit controversial whether it's better to use synthetic or \"natural\" keys (i.e. unique values that have real world meaning, e.g. SSN). I'm in the synthetic camp myself, but that's a flamewar beyond the scope of this thread.

Mike, I'll take a look at the template you mentioned and see if it makes the prospect of supporting composite keys easier, but it won't be soon. Real life and all that.
gekannt
Private First Class
 
Posts: 11
Joined: Tue Oct 18, 2005 11:55 am

Re:

Postby mdsrlz on Wed Jan 18, 2006 4:57 pm

gekannt wrote:
I'm sorry, but what is a "synthetic primary key"?

A synthetic key is a number that doesn't have any meaning in the problem domain, it's just used internally by the database. So to use a synthetic primary key, you'd add a new autoincremented integer column to your table, set that as the primary key, add a unique constraint for the columns from your old primary key, and change any foreign keys or constraints or whatever referring to your old composite key to refer to the new key.

It's a bit controversial whether it's better to use synthetic or "natural" keys (i.e. unique values that have real world meaning, e.g. SSN). I'm in the synthetic camp myself, but that's a flamewar beyond the scope of this thread.


Tks gekannt :~)

I also prefer use synthetic key, but I have an app using all tables of the data base, so I can't change it.

Bye.
mdsrlz
Lurker
 
Posts: 7
Joined: Fri Jan 13, 2006 6:31 pm
Location: Blumenau / SC / Brasil


Return to NHibernate

Who is online

Users browsing this forum: No registered users and 0 guests