Hi people!

Loosely related to point 4 (not-NHibernate)
<blatantpromotion;-)>
http://ajlopez.wordpress.com/2010/05/27/code-generation-with-ajgenesis-in-a-real-project/
</blatantpromotion;-)>

We could implement NHibernate (not needed yet), and generate the automatic
part again. The manual code is easily preserved.

The solution has many dozens of entities, and is actually deployed and the
development is active.

The key points:
- An abstract model (notably, the app born with a database, the initial
model was the database, and after months, we migrated to an abstract model,
and then, migrated from one helper library to another).
- Pragmatic code generation (generate the tedious part, or parts that have
many details, error-prone task...) (select your battle: other team I know,
choose to generate only the stored procedures).
- Generate the same code you had generated by hand (proud of it). The team
developed the templates and tasks.
- Manual code preserved
- Separate problem (ie. persistence) from solution (ADO.NET, NHibernate,
other library). Or technology (classic ASP.NET, ASP.NET MVC, and now, Java).

As a proof of concept, we are building a Java application, using practically
the same abstract model (other domain, other entities in model).

There are many opinions about code generation. My intention was to point to
a real project case (it's a private one, in other posts are "small" proof of
concepts demos).

Angel "Java" Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

On Thu, Sep 2, 2010 at 11:25 AM, Diego Mijelshon <[email protected]>wrote:

> 1. You can make NH generate the right parameter sizes by setting them
> explicitly. Example:
>
> query.SetParameter("someProperty", value, TypeFactory.GetStringType(100))
>
> 2. Nonsense. This is how ADO.NET executes queries. If that's a concern,
> you'd have to drop .NET completely.
> 3. That's a blanket statement. What would be a concrete example? What's an
> "unstable" SQL construction?
> 4. I happen to think exactly the opposite: code generation kinda works for
> small stuff and projects that are just starting. But it makes for harder to
> maintain / extend code in the long run.
>
> The conclusion is also devoid of actual facts.
>
>     Diego
>
>
>
> On Thu, Sep 2, 2010 at 10:37, Joseph Daigle <[email protected]>wrote:
>
>> Our company recently hired an outside consulting group to do an
>> assessment of our project. Part of this included a database
>> performance and tuning analysis by a very prominent member of the MS
>> SQL Server community. His report had a lot of great stuff in it. But
>> it also included some critical points surrounding the usage of
>> NHibernate.
>>
>> First of all, our project is a high volume OLTP system which includes
>> a number of legacy models and newer domain models. The more recently
>> rebuilt components use NHibernate to give us sufficient abstraction
>> from the database models, but still give us the power to properly
>> structure queries.
>>
>> I decided to enumerate many of the points that were brought up in the
>> report and from discussions with the consulting group to see what the
>> community thought. Essentially I’m looking for more ammunition.
>>
>> 1.      NHibernate generates ad-hoc queries which result in unnecessary
>> memory pressure on the procedure cache by incorrectly setting the
>> parameter sizes. Instead of setting the parameter size to the size of
>> the mapped column, it’s set to the size of the value.
>>
>> This is a pretty valid argument, and I still consider it a bug in
>> NHibernate. But you can work around this by setting the prepare_sql
>> configuration option. I don’t like this, and DBAs don’t like this. So
>> I’ve actually sub-classed the Sql client driver to make sure it always
>> sets the proper parameter size when generating the command. So I
>> believe this argument is not worth any weight.
>>
>> 2.      NHibernate generates Sql statements and wraps them in “EXEC
>> ExecuteSQL N’Select…” statements. This apparently masks similar
>> queries from most analysis tools, making harder for the DBA to do
>> performance analysis and tuning.
>>
>> This is valid, but I think it’s fairly nit-picky. It doesn’t directly
>> affect performance, and I think it’s just a DBA not likely the format
>> of the query NHibernate generates.
>>
>> 3.      “The biggest problem with NHibernate is the workarounds to achieve
>> scaling and performance goals often require awkward and unstable SQL
>> constructions.”
>>
>> This is probably the most valid argument. There are simply some SQL
>> statements that NHibernate cannot generate from criteria, HQL, or
>> LINQ. As such you end up using workarounds like correlated subqueries,
>> which aren’t always stable. The programmer ends up trying to tell SQL
>> Server how to retrieve a result set, instead of telling SQL Server
>> what the result set should look like and have it do the optimizations.
>>
>> However, in the cases where complex queries are required, there is
>> nothing stopping you from dropping down to the stored procedure level
>> and then mapping the result set back to an entity. I don’t think they
>> realize how trivial this is to do.
>>
>> 4.      The final argument was more development and ALM centric. This
>> group
>> is a big fan of template driven code generation for data access
>> layers. I think this works when you’re focusing on building database
>> schema first, or working with a legacy database model. But when doing
>> model or domain driven design, where you might start with classes and
>> work out from there, I think NHibernate is much better fit. I also
>> just don’t like code generation.
>>
>> But I can see the appeal from a perspective of refactoring. If you
>> need to change your persistence strategy, just push and button and
>> regenerate the code. Whether this is a good thing or not… I’m not
>> sure.
>>
>> Finally I’d like to quote the report:
>>
>> "Note that NHibernate is a good system for small-scale database
>> applications due to its ability to rapidly abstract the data for the
>> application. This was an excellent choice for the company in its early
>> years but the application has clearly grown beyond what NHibernate can
>> reasonably support."
>>
>> I would appreciate everyone’s thoughts, comments, or suggestions.
>>
>> Thanks,
>>
>> --
>> Joseph Daigle
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<nhusers%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to