views:

331

answers:

5

Hi, I am developing a enterprise software for a big company using Oracle. Major processing unit is planned to be developed in PL/SQL. I am wondered if there is any ORM like Hibernate for Java, but the one for PL/SQL. I have some ideas how to make such a framework using PL/SQL and Orcale system tables, but it is interesting - why no one have done this before? What do you think will that be effective in speed and memory consumption? Why?

+9  A: 

ORMs exist to provide an interface between a database-agnostic language like Java and a DBMS like Oracle. PL/SQL in contrast knows the Oracle DBMS intimately and is designed to work with it (and a lot more efficiently than Java + ORM can). So an ORM between PL/SQL and the Oracle DBMS would be both superfluous and unhelpful!

Tony Andrews
What I mean here is that I can create set of Oracle objects (using 'create or replace type FOO as object..' statements generated using script), that will ease the further development of the pl/sql software (those will basically contain CRUD operations). What do you think, will those objects perform efficiently?
Arino
I have never come across a situation where that would be helpful, and am pretty confident that the performance would not be as efficient as the PL/SQL code that didn't use objects. You would also quite likely lose the ability to perform set-based operations and bulk inserts/updates.
Tony Andrews
+2  A: 

As Tony pointed out ORMs really serve as helper between the App and Db context boundaries.

If you are looking for an additional level of abstraction at the database layer you might want to look into table encapsulation. This was a big trend back in the early 2000s. If you search you will find a ton of whitepapers on this subject.

Plsqlintgen still seems to be around at http://sourceforge.net/projects/plsqlintgen/

Ben Bahrenburg
What do you think is this technique is effective one?
Arino
I think it depends on the reason behind the abstraction and the size of the project. If you have 100s of tables it could quickly become an maintenance nightmare. Performance could also be an concern. In general I try to avoid this pattern unless it is the only way to meet security ( SOX, HIPPA, etc ) concerns.
Ben Bahrenburg
+3  A: 

Take a read through these two articles - they contain some interesting points

Ask Tom - Relational VS Object Oriented Database Design

Ask Tom - Object relational impedance mismatch

Paul James
A: 

Oracle is a Relation database and also has the ability to work as an object-oriented database as well. It does this by building an abstraction layer (fairly automatically) on top of the relational structure. This would seemingly eliminate the need for any "tool" as it is already built-in.

Adam Hawkes
A: 

This answer has some relevant thoughts on the pros and cons of wrapping your tables in pl/sql TAPIs (Table APIs) for CRUD operations.

http://stackoverflow.com/questions/3092041/understanding-the-differences-between-table-and-transaction-apis

There was also a good panel discussion on this at last years UK Oracle User Group - the overall conclusion was against using table APIs and for transaction APIs, for much the same reason - the strength of pl/sql is the procedural control of SQL statements, while TAPIs push you away from writing set-based SQL operations and towards row-by-row processing.

The argument for TAPI is where you may want to enforce some kind of access policy, but Oracle offers a lot of other ways to do this (fine-grained access control, constraints, triggers on insert/update/etc can be used to populate defaults and enforce that the calling code is passing a valid request).

I would definitely advise against wrapping tables in PL/SQL object types.

A lot of the productivity with pl/sql comes from the fact that you can easily define things in terms of the underlying database structure - a row record type can be simply defined as %ROWTYPE, and will be automatically impacted when the table structure changes.

 myRec myTable%ROWTYPE
 INSERT INTO table VALUES myRec;

This also applies to collections based over these types, and there are powerful bulk operations that can be used to fetch & insert whole collections.

On the other hand, object types must be explicitly impacted each time you want to change them - every table change would require the object type to be impacted and released, doubling your work.

It can also be difficult to release changes if you are using inheritance and collections of types (you can 'replace' a package, but cannot replace a type once it is used by another type).

This isn't putting OO PL/SQL down - there are places where it definitely simplifies code (i.e. avoiding code duplication, anywhere you would clearly benefit from polymorphism) - but it is best to understand and play to the strengths of the language, and the main strength is that the language is tightly-coupled to the underlying DB.

That said, I do often find myself creating procedures to construct a default record, insert a record, etc - often enough to have editor macros for it - but I've never found a good argument for automatically generating this code for all tables (a good way to create a lot of unused code??)

JulesLt