Wednesday, January 27, 2010

ORM Idiotizm

For the over 10 past years I have been a strong critic of ORM concept. I feel that majority of people just don't understand the root
of the problem with ORM, don't understand what ORM is for, and even should it be there in the first place. I truly think that it should not,
the whole concept of ORM is wrong and here is why. I'll be talking in very practical terms. 

What is ORM? ORM allows us to map relational entities (read "tables" with keys and references) into objects in your code. Sounds very cool.
Let me ask you a "stupid" question -  why do you need to have those objects in your code to begin with? Huh? No, wait, don't close this page, keep on
 reading....why? Ah...because you need to show the grid of customers then change selected customer and save it back to db.

 Ok, let's start from display grid(or any kind of list, such as a treeview), so grid is object-oriented piece of software that "draws" lines on screen (or HTML)
 that mimics a table, also it draws little string values in those "cells", so grid needs to get some data to draw. OK, but don't we have data in database? We do.
Can we read this data? We can. Can we read different column types? We can. Can we know what columns are in there(in database/table). Yes, we can. Can we build grid directly from database. We can.  Can we do this automatically relying on database meta-data (data about columns, sizes, requirement etc...) WE CAN.

So, why do we need stupid POJO or POCO objects in between to draw grids? We do not. We need a "smart adapter", - a class that is absolutely universal -
 it takes "data descriptor" (think of DataTable,DataSet,DataRow in .NET) and build grid columns including their default width, maybe even color to indicate importance, etc..
This class ("adapter") may also take custom style-rule set that will hide certain columns or make them smaller - but this is just for DISPLAY ONLY purpose.

Back in 1995 I have used client-server database and I needed to build an application with 200 data-entry screens. What I did, I created a grid-derivative that was "so smart" -
 in 90% of cases I just wrote a select SQL - formed a dataSource and then grid showed it to me in design time (I used Delphi 1) where I dragged and colored columns to make them look pretty. Thats it!  No Line of code was written in business layer, no line of code in the grid form, just NONE. No strings to configure, and when you add columns to database - they may or may not automatically appear in the grid for corresponding table, depending on 'AutoRebuildColumns' boolean property. It also worked much faster than Hibernate (that did not exist back then) because it did not create any redundant copies of data in memory(no POJO/POCO).

Same approach for displaying detail forms: textboxes, checkmarks, radios etc...  All you need is this: allow developer to place controls on form to satisfy client's particular layout requirements,
 wire-up every data-entry control DIRECTLY to database column by name (i'll explain how) and write NO BOILER PLATE CODE. If column "Sex" is required in table "Customer" then radio-button should automatically be named "SEX" and be required upon 'Save". You don't need to write any validation code, any "Validators" - this is all extra work and really not needed - everything is already explicitly defined in your database schema. 

How to connect , say textbox directly to TABLE.COLUMN in database? Easy - you need to write some "framework" code that make your textbox "smart" by associating this data-entry field with particular column by STRING NAME, make a property "FieldName", and then everything should be read from metadata and applied to "object-oriented" properties of a text box, such as: Readonly, MaxSize  etc...   Some properties do not exist in DB, i.e. "text color" but that can be specified by developer in concrete form.

You feel what I am getting at here? Yes, AUTOMATIC DATABASE REFLECTION, with 100% CUSTOMIZATION ability by developer in every screen, but this is much more rare that just displaying/saving data back and forth in "default way" - without special customization.

Ok, now another part - working with "BUSINESS" objects. The truth is that in may cases you just don't need a business object because you are interfacing with
 table that has limited functionality, column and row count (think US_STATES table). For complex objects such as "Patient Medical Record" Hibernate and the like dont do you much good anyway, reason being - you need to have 100% control over SQL code/stored procedures being sent to database, and yes HQL is a language of Hibernate, but wait, why do I need it, I already know PL/SQL or t-SQL and know it well, and it has operators that Hibernate does not even dream about (think of compilation hints, things like grouping sets, CONNECT BY etc...).  So when I save 'Patient Medical Record" I certainly use CRUD-like helpers but definitely not a monster like Hibernate or MS Entity framework.

One last thought -  when you use LINQ that you all love so much, don't forget that LINQ knows nothing about your collections in terms of indexes....binary searches...
 consequently it is all very slow linear search ..... some food for thought.... LINQ to SQL? I'd rather use SQL to C# (its a joke).

Let's use excavator to dig swimming pool and spoon to eat cake but not vice-versa.











Read this link below, it will open you eyes!

http://incubator.apache.org/empire-db/empiredb/hibernate.htm

21 comments:

Anonymous said...

This does make sense, if you think of your software pieces being considered as parts of relational model, NORMALIZATION RULES PROHIBIT repetition, so why would one repeat schema in: database, Hibernate on server, web service WSDL/SOAP layer, proxy on client, data adapter, typed data set and only then - grid on a client end.

Anonymous said...

Great rant. You know we are going to scaffolding, I guess this is what you are talking about here. After having spent 2 years writing stupid beans only to realize that type safe java objects are not really needed in majority of entry forms

Anonymous said...

agreed. our architects are brainwashed and make us use orms eveywhere. in the app that we build in java we have many mvc pages that we built orm classes for and they just lay there unnedded

Coach Factory said...

louboutin outlet, michael kors handbags clearance, air jordan, oakley vault, burberry outlet online, kate spade handbags, louis vuitton handbags, michael kors outlet online, ray ban sunglasses, cheap oakley sunglasses, michael kors outlet online, toms shoes, prada outlet, true religion outlet, jordan shoes, coach purses, longchamp handbags, michael kors outlet, polo ralph lauren outlet online, coach outlet store online, nike free, tiffany and co, polo ralph lauren outlet, prada handbags, oakley sunglasses, nike air max, longchamp handbags, true religion, nike free, kate spade outlet, nike shoes, tory burch outlet, nike air max, louis vuitton outlet online, coach outlet, coach factory outlet, true religion jeans, ray ban sunglasses outlet, air max, longchamp outlet, air max, gucci outlet, louboutin, cheap michael kors, chanel handbags

Coach Factory said...

lululemon outlet, ray ban, nike roshe, mont blanc, converse shoes, karen millen, michael kors, roshe run, nfl jerseys, nike huarache, birkin bag, beats by dre, mac cosmetics, hogan, louboutin, converse pas cher, ray ban pas cher, montre pas cher, michael kors, vans, north face jackets, lululemon, oakley pas cher, north face outlet, reebok outlet, michael kors, nike free, ralph lauren, nike trainers, louis vuitton, louis vuitton, hollister, hermes, timberland, abercrombie and fitch, supra shoes, new balance shoes, juicy couture outlet, mulberry, air max, lancel, hollister, north face, rolex watches, juicy couture outlet, burberry, wedding dresses, new balance pas cher, abercrombie and fitch, nike air max

Coach Factory said...

nike air max, air max pas cher, p90x3, converse, ugg boots, ferragamo shoes, giuseppe zanotti, louboutin, moncler, mcm handbags, air max pas cher, ralph lauren, ugg outlet, soccer jerseys, valentino shoes, herve leger, babyliss pro, moncler, moncler, jimmy choo, vans, asics gel, air max, moncler outlet, chi flat iron, canada goose outlet, uggs on sale, hollister, canada goose, instyler ionic styler, moncler, canada goose, insanity, marc jacobs, tn pas cher, ray ban, canada goose outlet, air max, soccer shoes, canada goose, bottega veneta, ghd, ugg, celine handbags, ugg, gucci, canada goose, ugg boots, oakley

mao yun said...

1
instyler ionic styler
cheap soccer jerseys
tiffany and co jewelry
ghd hair straighteners
louboutin shoes
valentino sale
asics running shoes
adidas shoes
hollister
michael kors outlet online
jordan 4
insanity
christian louboutin
air jordan concord
giuseppe zanotti sale
cheap nba jerseys
insanity max 30
lacoste outlet
abercrombie and fitch
soccer jerseys
salomon running shoes
christian louboutin outlet
coach outlet store online
toms outlet
hollister clothing store
toms outlet
kate spade handbags
polo lacoste pas cher
cheap snapbacks
adidas outlet
babyliss
fred perry sale
christian louboutin outlet
pandora charms
discount oakley sunglasses
mlb jerseys wholesale
salomon shoes
ralph lauren outlet
converse outlet
ray ban aviator sunglasses
michael kors uk
20150326maoqiuyun

Weiming Zhu said...

ugg boots
air jordan 13
air jordan shoes
beats headphones
bottega veneta outlet
burberry outlet
canada goose outlet
chanel outlet
cheap wedding dresses
coach outlet
dansko outlet
evening dresses
hermes belt
hermes birkin
hermes outlet
juicy couture outlet
kate spade outlet
mbt shoes
michael kors outlet
mizuno running
moncler coats
mulberry outlet
soccer shoes
nike outlet store
the north face outlet
oakley sunglasses
ray ban sunglasses
stuart weitzman boots
surpa sneakers
north face outlet
the north face clearance
the north face jackets
the north face outlet store
north face jackets
the north face uk
tommy hilfiger outlet
tory burch outlet
true religion jeans
vans shoes
ysl outlet

Meiqing Xu said...

20150623meiqing
louis vuitton
louis vuitton
fitflop footwear
oakley store
kate spade outlet
ralph lauren outlet
ray ban sunglasses
jordan 8 playoffs
oakley vault
toms outlet
www.louisvuitton.com
hollister
jordan concord 11s
michael kors outlet online
chanel bags
christian louboutin outlet
coach outlet
fitflops clearance
louboutin
louis vuitton outlet
coach outlet
coach outlet store online
marc jacobs handbags
toms promo code
oakley sunglasses wholesale
lebron james basketball shoes
prada
jeremy scott shoes
oakley sunglasses
abercrombie outlet
louis vuitton
discount oakley sunglasses
christian louboutin outlet
michael kors uk
ray ban wayfarer
concords 11
kd shoes
kate spade handbags
pandora charms
abercrombie & fitch

Wenhao Guo said...

ddddd0925fred perry polo, http://www.fredperrypoloshirts.com/
coach outlet online,coach purses,coach handbags,coach bags,coach handbags sale,coach handbags outlet
hollister,hollister canada,abercrombie and fitch,abercrombie,abercrombie fitch,abercrombie kids,a&f
nike air foamposite one,foamposite,foamposites,foamposite release 2015,foamposite sneakers,foamposites for sale,foamposite gold
ugg boots, http://www.uggboot.com.co/
links of london uk, http://www.linksoflondons.co.uk/
louis vuitton outlet online, http://www.louisvuittonoutlet.in.net/
rolex watches,rolex,watches for men,watches for women,omega watches,replica watches,rolex watches for sale,rolex replica,rolex watch,cartier watches,rolex submariner,fake rolex,rolex replica watches,replica rolex
ralph lauren,ralph lauren uk,ralph lauren outlet,ralph lauren outlet online,polo ralph lauren outlet,ralph lauren polo
dansko clogs, http://www.dansko-shoes.us/
kobe bryants shoes 2015, http://www.kobeshoes.us/
michael kors outlet store, http://www.michaelkorsoutletonlinstore.us.com/
monster beats, http://www.beats-headphones.in.net/
san antonio spurs, http://www.sanantoniospursjersey.com/
kobe bryant store, http://www.kobebryantshoes.in.net/
nfl jerseys wholesale, http://www.nfljerseys-wholesale.us.com/
new york knicks, http://www.newyorkknicksjerseys.com/
chanel handbags, http://www.chanelhandbags-outlet.us.com/

oakleyses said...

kate spade outlet online, nike air max, tory burch outlet online, ugg boots clearance, prada handbags, nike air max, ray ban sunglasses, michael kors handbags, chanel handbags, jordan shoes, nike outlet, longchamp outlet online, gucci handbags, christian louboutin, christian louboutin shoes, burberry outlet online, ugg outlet, oakley sunglasses, louis vuitton outlet, ray ban outlet, nike free, cheap oakley sunglasses, cheap ugg boots outlet, louis vuitton, longchamp outlet, michael kors outlet online, polo ralph lauren outlet, burberry outlet online, christian louboutin outlet, michael kors outlet online, oakley sunglasses, ray ban sunglasses, oakley vault, ugg australia, cheap ugg boots, red bottom shoes, replica watches, michael kors outlet, tiffany and co, tiffany jewelry, louis vuitton outlet online, replica watches, polo ralph lauren, prada outlet, louis vuitton handbags

oakleyses said...

guess pas cher, nike air max, nike roshe run, mulberry uk, coach outlet, true religion outlet, true religion outlet, new balance pas cher, abercrombie and fitch, longchamp, nike air max, scarpe hogan, air max pas cher, sac vanessa bruno, ray ban pas cher, nike roshe, north face, coach purses, burberry pas cher, nike free pas cher, lacoste pas cher, timberland pas cher, coach outlet, michael kors uk, michael kors, nike free, longchamp pas cher, tn pas cher, hollister uk, vans pas cher, true religion jeans, ray ban uk, true religion, michael kors outlet online, north face pas cher, hermes pas cher, air jordan, lululemon outlet online, hollister, michael kors canada, louboutin, nike blazer pas cher, kate spade outlet, coach outlet store online, oakley pas cher, converse pas cher, nike air force, ralph lauren uk, air max, ralph lauren pas cher

oakleyses said...

nike air max, longchamp, new balance outlet, oakley, mcm handbags, nike roshe, ferragamo shoes, nfl jerseys, asics shoes, ralph lauren, celine handbags, mont blanc pens, hollister, s6 cases, baseball bats, soccer jerseys, nike air huarache, p90x workout, hollister clothing store, bottega veneta, giuseppe zanotti, insanity workout, abercrombie and fitch, ghd, iphone cases, valentino shoes, mac cosmetics, herve leger, iphone 6 cases, iphone 5s cases, lululemon outlet, instyler ionic styler, north face jackets, vans outlet, wedding dresses, soccer shoes, north face jackets, jimmy choo shoes, iphone 6s plus cases, birkin bag, beats headphones, timberland boots, nike trainers, iphone 6 plus cases, louboutin, reebok shoes, babyliss, chi flat iron

oakleyses said...

pandora jewelry, swarovski uk, canada goose, moncler outlet, links of london uk, coach outlet, ugg boots, hollister canada, sac lancel, marc jacobs handbags, air max, pandora jewelry, converse, replica watches, vans, wedding dress, uggs outlet, canada goose pas cher, canada goose, uggs canada, louis vuitton uk, moncler, barbour, gucci, supra shoes, moncler outlet, canada goose, canada goose outlet, doke gabbana outlet, moncler, juicy couture outlet, sac louis vuitton, canada goose, canada goose outlet, montre femme, thomas sabo uk, ugg soldes, louis vuitton, louis vuitton pas cher, moncler, swarovski jewelry, michael kors outlet online, louis vuitton canada, barbour jackets, converse shoes, ugg, canada goose outlet, ugg, ray ban, karen millen, moncler

mmjiaxin said...

herve leger dresses
louis vuitton handbags outlet
coach outlet store
ralph lauren outlet
ray-ban sunglasses
kobe bryants shoes
tiffany and co
karen millen uk
coach outlet online
phone cases
rolex uk
nike free 5
swarovski crystal
louis vuitton handbags outlet
ray ban sunglasses
cheap oakley sunglasses
michael kors canada
nba jerseys
mlb jerseys
michael kors handbags
mm1202

方松腾 said...

ugg boots
cheap oakley sunglasses
true religion sale
air jordan 11 free shipping
toms outlet
louis vuitton outlet
michael kors outlet,michael kors outlet online,michael kors,kors outlet,michael kors handbags,michael kors outlet online sale,michael kors handbags clearance,michael kors purses,michaelkors.com,michael kors bags,michael kors shoes,michaelkors,cheap michael kors
north face jackets
ferragamo shoes
soccer jerseys,soccer jerseys wholesale,soccer jerseys cheap,soccer jerseys for sale,cheap soccer jersey,usa soccer jersey,football jerseys
ugg boots on sale
vans sneakers
oakley sunglasses
fitflops outlet
coach outlet online,coach purses,coach handbags,coach bags,coach handbags sale,coach handbags outlet

safa and Marwa said...

شركة الصفا والمروه لخدمات التنظيف
شركة تنظيف بالدمام
شركة تسليك مجاري بالدمام
شركة تنظيف شقق بالدمام
شركة تنظيف فلل بالدمام
شركة مكافحة حشرات بالدمام
شركة كشف تسربات المياة بالدمام

شركة مكافحة النمل الابيض بالخبر
شركة تنظيف بالخبر
شركة كشف تسربات المياة بالخبر
شركة مكافحة النمل الابيض بالخبر
شركة تسليك مجاري بالخبر

شركة تسليك مجاري بالجبيل
شركة كشف تسربات المياة بالجبيل
شركة تسليك مجاري بالاحساء
شركة تسليك مجاري بالرياض
شركة تسليك مجاري بجدة
شركة تسليك مجاري بتبوك
شركة تسليك مجاري بالقطيف
شركة كشف تسربات المياة بالاحساء
شركة كشف تسربات المياة بالقطيف
شركة تسليك مجاري ببقيق

شركة تسليك مجاري بالباحة
شركة تسليك مجاري بالخفجي
شركة تسليك مجاري بعنك-سيهات
شركة تسليك مجاري بالنعيرية
شركة مكافحة النمل الابيض بالخبر

شركة مكافحة النمل الابيض بالدمام
شركة تسليك مجاري بالدمام

Cran Kate said...

Tory Burch Flats Marc Jacobs Handbags Jimmy Choo Shoes Jimmy Choos True Religion Outlet ED Hardy Outlet
Burberry Belt Tory Burch Boots Louis Vuitton Belt Ferragamo Belt Marc Jacobs Handbags Lululemon Outlet Christian Louboutin Shoes True Religion Outlet Tommy Hilfiger Outlet
Michael Kors Outlet Coach Outlet Red Bottoms Kevin Durant Shoes New Balance Outlet Adidas Outlet Coach Outlet Online Stephen Curry Jersey Vans Outlet Ralph Lauren Outlet
Ugg Boots Sale UGGS For Women Skechers Go Walk Adidas Yeezy Boost Adidas Yeezy Adidas NMD Coach Outlet North Face Outlet Ralph Lauren Outlet Puma Outlet Polo Outlet

chenlina said...

michael kors outlet
ugg outlet
ray bans
fitflop shoes
seattle seahawks jerseys
cheap ray ban sunglasses
kate spade outlet
los angeles clippers jerseys
adidas outlet
oakley sunglasses
chenlina20161027

Unknown said...

toms outlet
lebron james shoes
nike blazer pas cher
adidas nmd
cheap nba jerseys
pandora outlet
washington redskins jerseys
nike huarache
fitflops sale clearance
ghd hair straighteners

Unknown said...

michael kors handbags wholesale
salomon shoes
the north face
chargers jerseys
raiders jerseys
toms shoes
hermes belts
skechers shoes
san antonio spurs jerseys
replica rolex