• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Complex Business Rules

 
raj joe
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.I have heard of OR mapping tools from many years.But Please let me know how are they different from Entity Beans.

2.if i have complex business rules ,then will such tools help or an SP
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. They are a solution to the same problem (i.e. the Object-Relational Impedence Mismatch) but don't contain the unecessary baggage of Entity Beans. In particular, they don't require an EJB container.

2. Complex business rules don't belong in the persistence layer. Arguably they could exist in the database (in the form of Stored Procedures) for performance reasons, but by-and-large all business logic belongs in your application, not the database.
 
raj joe
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
1. They are a solution to the same problem (i.e. the Object-Relational Impedence Mismatch) but don't contain the unecessary baggage of Entity Beans. In particular, they don't require an EJB container.

2. Complex business rules don't belong in the persistence layer. Arguably they could exist in the database (in the form of Stored Procedures) for performance reasons, but by-and-large all business logic belongs in your application, not the database.


Thanks for info.
But I have a application wherein i access 5-8 tables to process a single request.In OR mapping i understnd
1.I have to have all these 8 tables map
2.Then access the classes of these tables,
3.Do by business logic
4.The respond.

whereas i feel i could have executed an single SP call and get the response back.What are your thoughts
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

whereas i feel i could have executed an single SP call and get the response back.What are your thoughts

You could do it this way of course. But by doing this you have added another location for business logic (i.e. in the database) which will need written, tested and maintained, in addition to your application. In order to debug what is happening in your app. you will need to check more than one source, which adds complication. This also implies that changing the database/adding support for another database requires you re-implement the stored procedure in whatever database specific language that database uses.

Performance is pretty much the only reason I would choose to use Stored Procedures. And performance is only a valid requirement if it is specifically specified for (with target metrics), rather than as a general concern.
 
Loren Rosen
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With most ORM tools there doesn't have to be a 1-to-1 relationship between database tables and Java classes.

Also, with most tools you can fetch data from multiple tables in a single request (that is, do database joins). The potentially big win with a stored procedure is that you may save the cost of transferring the data between the database server and the application.
 
raj joe
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Loren Rosen:
With most ORM tools there doesn't have to be a 1-to-1 relationship between database tables and Java classes.

Also, with most tools you can fetch data from multiple tables in a single request (that is, do database joins). The potentially big win with a stored procedure is that you may save the cost of transferring the data between the database server and the application.



I have scenerios wherein i have several steps to retrive data and some updates .In one single call to SP i execute all the business rules (Say get data from table B if match in A etc,like wise till table K then update table X Y Z and out out)

If I had to do that in OR mapping from app.I first execute a call to get table then make seperate 3 calls to update tables X Y Z .Can updations to multiple tables made with one single call.
 
Michael D. Brown
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by raj joe:

If I had to do that in OR mapping from app.I first execute a call to get table then make seperate 3 calls to update tables X Y Z .Can updations to multiple tables made with one single call.


I'm not going to claim to know every ORM tool out there, however, I know that Hibernate allows you to define complex queries that update multiple tables either in mapping files or dynamically.

The advantage of using an ORM comes from the possibilities that come from using a rich domain model. You can capture business rules and special cases within your Domain Hierarchy and let your mapping worry about how to persist the data.
 
Loren Rosen
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To put this slightly differently, it depends on the ORM tool and the details of your model, but it's quite possible that you could get the business rule code in the middle tier to execute the same queries as does the business rule stored procedure. The stored procedure would be modestly more efficient but the difference might be enough to trump other engineering considerations.
 
Michael Duffy
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there's some risk in embedding business rules in your persistence layer. My preference would be to have that logic in a service layer. Let the persistence layer worry only about CRUD operations; have several operations that are invoked by the service layer or domain model as the business rules demand.

%
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic