File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes General Computing and the fly likes question about persistence layer and business logic layer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "question about persistence layer and business logic layer" Watch "question about persistence layer and business logic layer" New topic
Author

question about persistence layer and business logic layer

jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
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

Joined: Aug 16, 2005
Posts: 13875
    
  10

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4637
    
    5

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

Joined: May 20, 2008
Posts: 180
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

Joined: Jun 25, 2001
Posts: 15641
    
  15

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
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

Joined: May 20, 2008
Posts: 180
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

Joined: May 20, 2008
Posts: 180
i think i got the whole picture of how everything works now

thank you
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

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

Joined: Aug 11, 2007
Posts: 4637
    
    5

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

Joined: May 20, 2008
Posts: 180
thank you guys

i think now i have a better understand of it
Val Huber
Greenhorn

Joined: Aug 14, 2011
Posts: 1
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about persistence layer and business logic layer
 
Similar Threads
How to add Business Logic layer in GWT
Design choices
Using Java EE entities over DAO
EJB - Local interface
doubt in security - username and password.