Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4119676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:07:16+00:00 2026-05-20T23:07:16+00:00

While using ORM tools such as Hibernate, I’ve found it is advantageous to keep

  • 0

While using ORM tools such as Hibernate, I’ve found it is advantageous to keep all business logic out of my business objects and instead keep it in a service layer. The service layer creates the business object POJOs, manipulates them, and uses DAOs to save them. But isn’t this in a way taking a step backwards from the object oriented nature of Java?

My stack includes Spring with Hibernate for DI, transactions, and persistence. My DAOs are injected into my service layer, not into any POJOs.

Recently I read Martin Fowler’s accounting patterns document on building flexible accounting systems. I believe it was written before the Spring/Hibernate/DI/ORM craze. It describes objects that contain business logic. These objects use inheritance and composition in elegant ways that make sense.

By putting the logic into classes, it can be partitioned into neat units that only pertain to one specific scenario. In my service layer I end up having lots of different methods, each which deals with a different scenario. But it is far from object oriented.

In Martin Fowler’s accounting patterns document, he describes a base class of AccountingEvent. This class might have subclasses such as UsageEvent and InstallationEvent.

UsageEvent:

  • UsageEvent occurs when a meter reader records your electricity usage
  • Customer’s ServiceAgreement is looked up
  • The appropriate PostingRules are found in the service agreement for this type of event and for this particular time period. Rules and rates can change over time, so multiple PostingRules exist for any given type of event.
  • The UsageEvent and PostingRules determine what actions need to take place, such as creating one or more AccountingEntry objects.
  • An AccountingEntry is created to bill for the usage with logic contained in the PostingRule. This could be as simple as rate * usage, but is probably much more complex, based on time of day, commitment levels (big businesses might get discounts), low income households, etc.
  • Additional AccountingEntrys are created to bill for taxes, provide credits, etc.

InstallationEvent:

  • InstallationEvent occurs when a technician activates power to a building.
  • Service agreement and PostingRules are found
  • Appropriate AccountingEntrys are created
  • Much different logic and rules are used than in UsageEvent

The point is that there are many different types of AccountingEvents and PostingRules, each of which knows precisely what to do for a specific situation. These objects are easily interchangeable using interfaces. I can kick of everything by simply issuing the command someAccountingEvent.process().

I’m unclear on the best way to get some of this elegance back when I have to create and save entities within the service layer. I don’t want to inject my DAOs into my POJOs, which would add extra dependencies to them and potentially make them much heavier weight objects. But how would I best model something like this in my service layer where I can inject DAOs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:07:17+00:00Added an answer on May 20, 2026 at 11:07 pm

    You might be talking about what’s referred to as an "Anemic domain model". I have previously answered a question on the topic which points to a blog article about how to inject services into model instances which Hibernate it retrieving.

    Spring and the Anemic Domain Model

    The referenced blog article is Domain Driven Design with Spring and Hibernate

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I was trying to create a application using Hibernate as ORM. So while
I am using the JPA(hibernate) for the ORM and c3po for connection pooling. While
i am using hibernate as ORM tool, and while loading the data from table
While using perl debugger, is there any way to step out of the current
I have the following code, using Django ORM routes =Routes.objects.filter(scheduleid=schedule.id).only('externalid') t_list = [(route.externalid, route.vehicle.name)
A while back I wrote an ORM layer for my .net app where all
I have created a seam applcation with Hibernate(default) a ORM provider. While persisting an
Long time ago, I was creating a mini ORM using reflection. While reading about
I am using Hibernate as the ORM for a database that has a number
While using Google chrome if I shut down it unexpectedly. like turn of pc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.