<p>In what domains do each of these software architectures shine or fail?</p>

<p>Which key requirements would prompt you to choose one over the other?</p>

<p>Please assume that you have developers available who can do good object oriented code as well as good database development.</p>

<p>Also, please avoid holy wars :) all three technologies have pros and cons, I'm interested in where is most appropriate to use which.</p>

[{'answer_id': 76442, 'author': 'Ryan Lanciaux', 'author_id': 1385358, 'author_profile': 'https://Stackoverflow.com/users/1385358', 'pm_score': 3, 'selected': False, 'text': '<p>I agree that there are pros and cons to everything and a lot depends on your architecture. That being said, I try to use ORM\'s where it makes sense. A lot of the functionality is already there and usually they help prevent SQL Injection (plus it helps avoid re-inventing the wheel).</p>\n\n<p>Please see these other two posts on the topic (dynamic SQL vs \nstored procedures vs ORM) for more information</p>\n\n<p><strong>Dynamic SQL vs. stored procedures</strong><br>\n<a href="https://stackoverflow.com/questions/22907/which-is-better-ad-hoc-queries-or-stored-procedures">Which is better: Ad hoc queries, or stored procedures?</a></p>\n\n<p><strong>ORMs vs. stored procedures</strong><br>\n<a href="https://stackoverflow.com/questions/50346/why-is-parameterized-sql-generated-by-nhibernate-just-as-fast-as-a-stored-proce">Why is parameterized SQL generated by NHibernate just as fast as a stored procedure?</a></p>\n'}, {'answer_id': 76573, 'author': 'Nate Kohari', 'author_id': 1282, 'author_profile': 'https://Stackoverflow.com/users/1282', 'pm_score': 2, 'selected': False, 'text': '<p>ORMs and code generators are kind of on one side of the field, and stored procedures are on another. Typically, it\'s easier to use ORMs and code generators in greenfield projects, because you can tailor your database schema to match the domain model you create. It\'s much more difficult to use them with legacy projects, because once software is written with a "data-first" mindset, it\'s difficult to wrap it with a domain model.</p>\n\n<p>That being said, all three of the approaches have value. Stored procedures can be easier to optimize, but it can be tempting to put business logic in them that may be repeated in the application itself. ORMs work well if your schema matches the concept of the ORM, but can be difficult to customize if not. Code generators can be a nice middle ground, because they provide some of the benefits of an ORM but allow customization of the generated code -- however, if you get into the habit of altering the generated code, you then have two problems, because you will have to alter it each time you re-generate it.</p>\n\n<p>There is no one true answer, but I tend more towards the ORM side because I believe it makes more sense to think with an object-first mindset.</p>\n'}, {'answer_id': 76655, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Stored Procedures</strong></p>\n\n<ul>\n<li><strong>Pros:</strong> Encapsulates data access code and is application-independent</li>\n<li><strong>Cons:</strong> Can be RDBMS-specific and increase development time</li>\n</ul>\n\n<p><strong>ORM</strong></p>\n\n<p><em>At least some ORMs allow  mapping to stored procedures</em></p>\n\n<ul>\n<li><strong>Pros:</strong> Abstracts data access code and allows entity objects to be written in domain-specific way</li>\n<li><strong>Cons:</strong> Possible performance overhead and limited mapping capability</li>\n</ul>\n\n<p><strong>Code generation</strong></p>\n\n<ul>\n<li><strong>Pros:</strong> Can be used to generate stored-proc based code or an ORM or a mix of both</li>\n<li><strong>Cons:</strong> Code generator layer may have to be maintained in addition to understanding generated code</li>\n</ul>\n'}, {'answer_id': 76810, 'author': 'Craig Trader', 'author_id': 12895, 'author_profile': 'https://Stackoverflow.com/users/12895', 'pm_score': 5, 'selected': True, 'text': "<p>Every one of these tools provides differing layers of abstraction, along with differing points to override behavior.  These are architecture choices, and all architectural choices depend on trade-offs between technology, control, and organization, both of the application itself and the environment where it will be deployed.</p>\n\n<ul>\n<li><p>If you're dealing with a culture where DBAs 'rule the roost', then a stored-procedure-based architecture will be easier to deploy.  On the other hand, it can be very difficult to manage and version stored procedures.</p></li>\n<li><p>Code generators shine when you use statically-typed languages, because you can catch errors at compile-time instead of at run-time.</p></li>\n<li><p>ORMs are ideal for integration tools, where you may need to deal with different RDBMSes and schemas on an installation-to-installation basis.  Change one map and your application goes from working with PeopleSoft on Oracle to working with Microsoft Dynamics on SQL Server.</p></li>\n</ul>\n\n<p>I've seen applications where Generated Code is used to interface with Stored Procedures, because the stored procedures could be tweaked to get around limitations in the code generator.</p>\n\n<p>Ultimately the only correct answer will depend upon the problem you're trying to solve and the environment where the solution needs to execute.  Anything else is arguing the correct pronunciation of 'potato'.</p>\n"}, {'answer_id': 76839, 'author': 'Sklivvz', 'author_id': 7028, 'author_profile': 'https://Stackoverflow.com/users/7028', 'pm_score': 3, 'selected': False, 'text': '<p>I\'ll add my two cents:</p>\n\n<p><strong>Stored procedures</strong></p>\n\n<ul>\n<li>Can be easily optimized</li>\n<li>Abstract fundamental business rules, enhancing data integrity</li>\n<li>Provide a good security model (no need to grant read or write permissions to a front facing db user)</li>\n<li>Shine when you have many applications accessing the same data</li>\n</ul>\n\n<p><strong>ORMs</strong></p>\n\n<ul>\n<li>Let you concentrate only on the domain and have a more "pure" object oriented approach to development</li>\n<li>Shine when your application must be cross db compatible</li>\n<li>Shine when your application is mostly driven by behaviour instead of data</li>\n</ul>\n\n<p><strong>Code Generators</strong></p>\n\n<ul>\n<li>Provide you similar benefits as ORMs, with higher maintenance costs, but with better customizability.</li>\n<li>Are generally superior to ORMs in that ORMs tend to trade compile-time errors for runtime errors, which is generally to be avoided</li>\n</ul>\n'}, {'answer_id': 105417, 'author': 'Kevin Pauli', 'author_id': 19269, 'author_profile': 'https://Stackoverflow.com/users/19269', 'pm_score': 2, 'selected': False, 'text': '<p>You forgot a significant option that deserves a category of its own: a hybrid data mapping framework such as <a href="http://ibatis.apache.org/" rel="nofollow noreferrer">iBatis</a>.</p>\n\n<p>I have been pleased with iBatis because it lets your OO code remain OO in nature, and your database remain relational in nature, and solves the impedance mismatch by adding a third abstraction (the mapping layer between the objects and the relations) that is responsible for mapping the two, rather than trying to force fit one paradigm into the other.</p>\n'}]
['https://Stackoverflow.com/questions/76395', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7028/']