• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about persistence layer and business logic layer

 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. persistence layer is a group of files which is used to communicate between the application and DB.

2. business logic layer is the rules of how to retrieve the data information from the database, and then the sever takes those information to display on the user presentation layer.

These 2 layers look so similar

what is the difference between them?

thank you
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The persistence layer deals with persisting (storing and retrieving) data from a data store (such as a database, for example).

The business logic layer contains contains code which works with the data, processing it according to the rules of the business logic.

These are two completely different things.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, the Business domain objects have names like "Customer" or "Order" and they use the persistance layer to manage the fields in the Customer object into/out of the database.

The Business objects should not be one-to-one with the database tables. The Customer may have one or more addresses (shipping, billing, headquarters) but the way that's stored in the database should be unknown and unknowable to users of the Customer object
 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you guys for replying!

since i am working with hibernate and java.

so the persistence layers are the entity classes

and the business logic rules are the hibernate sessions which are used to customize how to retrieving the data

am i right?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the persistence layer is the set of classes that manage the actual reading and writing of data to persistent storage - the DAOs and other data service objects.

The business logic should ideally never know how that data gets read or written. It should use the persistence layer to get and save the data, but its function is to do the abstract functions of the business such as creating a new account (but not the Hibernate functions of actually storing or retrieving account records), calculating service fees and penalties, calculating shipping fees, managing inventory, creating picking and packing lists and so forth.
 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so basically hibernate sessions are the persistence layer which used to copy the values of the data from the database to the java entity class, or mapping the java classes back to the database.

so what about those entity classes and which layer do they belong to?

i guess they are belonged to the persistence layer

am i right?
 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh, one more thing.

i understand the concept of the business logic now.

since i am using java, hibernate, google web tookit(gwt) and extjs, oracle database. which part of those are responsible for the business logic tier?

thank you
 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think i got the whole picture of how everything works now

thank you
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jim li:
since i am using java, hibernate, google web tookit(gwt) and extjs, oracle database. which part of those are responsible for the business logic tier?

None of these things are the business logic layer. Those are just frameworks and libraries which you use in your software.

The business logic layer is typically the part of the software that you write yourself, and that contains the rules specific to your business. For example, a class that calculates the price of an item, taking maybe a discount and tax into account.

Note that not everything always fits exactly in the idea of layers. Entity classes for example, such as Person or Customer, that contain the data that your application work on, are used by both the business logic layer and the persistence layer. It's hard to say to which layer they really belong.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You, the developer, is responsable for the business layer. That's the heart of the application. Its what makes it a payroll application, or a medical records application.

The rest are tools to help you do the hard part, which is the domain specific business layer code.
 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you guys

i think now i have a better understand of it
 
Val Huber
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been a long time since your question, but it is a good one. I view presentation logic as all the controller actions to read and write data. The business logic is the consequences of writing - validating, computing, actions such as sending mail etc.

Frameworks provide mechanisms for you to write this logic. They don't write it for you.

Business Logic sounds simple, but it quickly results in lots of code. For example, a simple customer / order / item rollup to check customer credit takes about 10 pages of code, once you handle all of the related uses cases (deleting an order, deleting a line item, changing the assign part, etc etc).

Hope that helps. And, there do exist simpler ways of getting the business logic done, if you are using Hibernate.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic