Welcome!

Java IoT Authors: Pat Romanski, Elizabeth White, Liz McMillan, Carmen Gonzalez, Yeshim Deniz

Related Topics: Java IoT

Java IoT: Article

Java J2EE Hibernate Extreme Makeover: Architecture Edition

Large-scale refactoring with Spring and Hibernate

In the past few years there has been a proliferation of frameworks that allow for lighter, faster, and loosely coupled Java projects. These frameworks not only let you decouple your Java project from the application server for unit testing, they also allow for more agile refactoring, testing, and design techniques. This article will focus on telling the story of a large-scale refactoring effort implementing Spring and Hibernate as the underlying infrastructure tools. For those living under an abacus Spring is a J2EE framework built to handle many of the plumbing issues on a typical J2EE application. Hibernate is a popular Open Source Java object/relational persistence framework.

Bad EJB, No Donut
The last few years has produced a legion of J2EE applications tightly coupled to everyone's two favorite saviors, the Enterprise Java Bean (EJB) and the application container. Developers have tied their proverbial hands by coupling their code directly to these two Java mainstays. Many J2EE applications have been over-engineered and deemed overly complex by relying on these mainstays with few architectural best-practice guidelines to follow. Articles have been written and battle lines drawn around why and how this unfortunate series of events came to fruition.

Fortunately, there are now tools that provide ways to enable loose coupling and promote "simpler" architectures. Loose coupling encourages things like unit testing, test-driven development (TDD), and dependency injection. TDD is an approach to development that combines test-first development and constant refactoring. Dependency injection lets you inject dependent objects into your wired Java classes at runtime.

The First Step Is Admitting You Have A Problem
Everyone has probably experienced one or more applications built using the paradigm "'the more J2EE components the better." One of these applications was delivered to my doorstep for an extreme architecture makeover. The application owner's loose requirements were as follows:

  • Scalable and reliable
  • Flexible while resilient enough to support product changes
  • Easy to integrate and test
  • Loosely coupled so that disparate groups can work on separate components while simultaneously working on the application as a whole
  • Enabling high developer productivity
Now, I understand that these requirements are ubiquitous requests for most applications and are almost assumed out of the gate. They can almost be seen as "infrastructure" requirements. Still, they're requirements and the right tools need to be used to satisfy them. Putting on my architect hat we came up with five problem areas that were symptoms of why these requirements aren't being met. From these symptoms we derived their root causes and solutions. Table 1 is a matrix showing our findings.

As you can see all of these issues had nothing to do with how the application dealt with business logic. They were solely infrastructure problems that had to be resolved for the application to reach a higher level of software maturity. Follow along as we see what an extreme makeover entails.

Patient Diagnosis - Condition Serious
The application needing the makeover wasn't small and continued to grow every day. A high-calorie diet of EJBs, deployment descriptors and other various J2EE infrastructure files was the norm. It had over 1,600 Java files, 50 entity beans, and over 20 stateless beans (that served mainly as entry points into the application for transactional boundaries). The application's main functions were order provisioning and workflow. It played an integral part in a service-oriented architecture (SOA) that encompassed over 25 Web Services. The software build and deployment cycle to the application server took over 15 minutes. I guess you could call it obese.

There were zero out-of-container unit tests. The only existing tests were written using Cactus, which is a unit-testing framework for executing server-side code. Loosely translated that means that by choosing tools like Cactus your code has to be deployed to the application server to be tested. I personally feel that tools like Cactus enable or even promote bad habits like not having tests that can be run straight from your integrated development environment (IDE).

After reviewing all of the symptoms, a diet of Spring and Hibernate was prescribed. These technologies were primarily chosen for their ability to solve given symptoms. The following is a diary of the patient's miraculous transformation from emergency room to recovery room. Each symptom was typically remedied in one software iteration. The refactoring project took about five iterations over a period of five months, with between 2-4 infrastructure developers working on it at any given time. As the refactoring took place, the business logic developers went full steam ahead sprinkling functionality goodness across the application. The refactoring team's core focus was solely on the infrastructure. A good analogy is that the engines were changed out on the airplane while it was still in flight.

Remember the Food Pyramid for Healthy Living
Symptom: Developers were interfering with each other
Root Cause: Poor code structure and no separation of concerns
Solution: Modularize the code base and adopt a layered architecture

Having a tightly coupled code base can wreak havoc on developer productivity. Interaction complexity is extremely high and one code change can potentially affect multiple areas of the code. The application can be classified as brittle and development typically takes much longer than in a layered architecture. Building layers in your architecture will lead to a well-defined separation of concerns allowing each layer to be understood as a coherent whole. Interfaces are typically used as the contract between each layer. By implementing the Interface pattern your application can now substitute each layer with an alternative implementation. The benefits of this paradigm will be discussed in greater detail in the next symptom. The first step taken to modularizing the code base was to break the project into five distinct sub-projects. These sub-projects were compiled according to their dependencies. This enforced that each layer only knew about the ones below it. Figure 1 offers a before and after picture of the logical code base.

Notice that each distinct functional area dictates where the layer boundaries are. These are not revolutionary concepts, just good pragmatic architectural decisions. A loosely coupled architecture makes adopting an Inversion of Control (IOC) container like Spring much easier than not. The next symptom's solution would be hard if not impossible to implement without a layered architecture.

Take Your Injections
Symptom: Unable to consistently run tests in a development environment or gather Web Services metrics.
Root Cause: Reliance on external Web Services availability
Solution: Dependency injection, aspect-oriented programming (AOP), and mock objects

With the advent of SOA came the troublesome deal of unit testing. As if testing wasn't hard enough, you're now reliant on someone else's application to execute unit tests. Another problem with a SOA is the inability to audit your service calls without intrusive metrics-gathering code throughout your application. The first order of business was to create an external provider layer with well-defined interfaces. Figure 2 shows the use of the façade pattern for all of the external Web Service calls done by the application. Classes in the external provider layer implement an interface and are injected into plain old Java object (POJO) business services.

More Stories By Franz Garsombke

Franz Garsombke has been developing and architecting enterprise software solutions in Colorado for the last eleven years and is currently employed at Rally Software. Franz is a huge proponent of open source frameworks and is passionate about developing and delivering simple, quality, pragmatic applications. He is proud to be the co-founder of a Java Bean mapping framework (http://dozer.sourceforge.net) and can be reached at [email protected] or on his mountain bike.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
JDJ News Desk 10/20/05 07:06:17 PM EDT

Java J2EE Hibernate Extreme Makeover: Architecture Edition. In the past few years there has been a proliferation of frameworks that allow for lighter, faster, and loosely coupled Java projects. These frameworks not only let you decouple your Java project from the application server for unit testing, they also allow for more agile refactoring, testing, and design techniques. This article will focus on telling the story of a large-scale refactoring effort implementing Spring and Hibernate as the underlying infrastructure tools. For those living under an abacus Spring is a J2EE framework built to handle many of the plumbing issues on a typical J2EE application. Hibernate is a popular Open Source Java object/relational persistence framework.

@ThingsExpo Stories
SYS-CON Events announced today that Peak 10, Inc., a national IT infrastructure and cloud services provider, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Peak 10 provides reliable, tailored data center and network services, cloud and managed services. Its solutions are designed to scale and adapt to customers’ changing business needs, enabling them to lower costs, improve performance and focus intern...
Everywhere we turn in our industry we can find strong opinions about the direction, type and nature of cloud’s impact on computing and business. Another word that is used in every context in our industry is “hybrid.” In his session at 20th Cloud Expo, Alvaro Gonzalez, Director of Technical, Partner and Field Marketing at Peak 10, will use a combination of a few conceptual props and some research recently commissioned by Peak 10 to offer a real-world consideration of how the various categories of...
Five years ago development was seen as a dead-end career, now it’s anything but – with an explosion in mobile and IoT initiatives increasing the demand for skilled engineers. But apart from having a ready supply of great coders, what constitutes true ‘DevOps Royalty’? It’ll be the ability to craft resilient architectures, supportability, security everywhere across the software lifecycle. In his keynote at @DevOpsSummit at 20th Cloud Expo, Jeffrey Scheaffer, GM and SVP, Continuous Delivery Busine...
Detecting internal user threats in the Big Data eco-system is challenging and cumbersome. Many organizations monitor internal usage of the Big Data eco-system using a set of alerts. This is not a scalable process given the increase in the number of alerts with the accelerating growth in data volume and user base. Organizations are increasingly leveraging machine learning to monitor only those data elements that are sensitive and critical, autonomously establish monitoring policies, and to detect...
SYS-CON Events announced today that SoftLayer, an IBM Company, has been named “Gold Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2016, at the Javits Center in New York, New York. SoftLayer, an IBM Company, provides cloud infrastructure as a service from a growing number of data centers and network points of presence around the world. SoftLayer’s customers range from Web startups to global enterprises.
The 21st International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Digital Transformation, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
Multiple data types are pouring into IoT deployments. Data is coming in small packages as well as enormous files and data streams of many sizes. Widespread use of mobile devices adds to the total. In this power panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists will look at the tools and environments that are being put to use in IoT deployments, as well as the team skills a modern enterprise IT shop needs to keep things running, get a handle on all this data, and deli...
SYS-CON Events announced today that Systena America will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Systena Group has been in business for various software development and verification in Japan, US, ASEAN, and China by utilizing the knowledge we gained from all types of device development for various industries including smartphones (Android/iOS), wireless communication, security technology and IoT serv...
SYS-CON Events announced today that Loom Systems will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Founded in 2015, Loom Systems delivers an advanced AI solution to predict and prevent problems in the digital business. Loom stands alone in the industry as an AI analysis platform requiring no prior math knowledge from operators, leveraging the existing staff to succeed in the digital era. With offices in S...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend @CloudExpo | @ThingsExpo, June 6-8, 2017, at the Javits Center in New York City, NY and October 31 - November 2, 2017, Santa Clara Convention Center, CA. Learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
SYS-CON Events announced today that EARP Integration will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. EARP Integration is a passionate software house. Since its inception in 2009 the company successfully delivers smart solutions for cities and factories that start their digital transformation. EARP provides bespoke solutions like, for example, advanced enterprise portals, business intelligence systems an...
We build IoT infrastructure products - when you have to integrate different devices, different systems and cloud you have to build an application to do that but we eliminate the need to build an application. Our products can integrate any device, any system, any cloud regardless of protocol," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA
SYS-CON Events announced today that Enzu will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY, and the 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enzu’s mission is to be the leading provider of enterprise cloud solutions worldwide. Enzu enables online businesses to use its IT infrastructure to their competitive ad...
Existing Big Data solutions are mainly focused on the discovery and analysis of data. The solutions are scalable and highly available but tedious when swapping in and swapping out occurs in disarray and thrashing takes place. The resolution for thrashing through machine learning algorithms and support nomenclature is through simple techniques. Organizations that have been collecting large customer data are increasingly seeing the need to use the data for swapping in and out and thrashing occurs ...
SYS-CON Events announced today that Interoute has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Interoute is the owner operator of Europe's largest network and a global cloud services platform, which encompasses over 70,000 km of lit fiber, 15 data centers, 17 virtual data centers and 33 colocation centers, with connections to 195 additional partner data centers. Our full-service Unifie...
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm.
SYS-CON Events announced today that delaPlex will exhibit at SYS-CON's @CloudExpo, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. delaPlex pioneered Software Development as a Service (SDaaS), which provides scalable resources to build, test, and deploy software. It’s a fast and more reliable way to develop a new product or expand your in-house team.
SYS-CON Events announced today that Progress, a global leader in application development, has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Enterprises today are rapidly adopting the cloud, while continuing to retain business-critical/sensitive data inside the firewall. This is creating two separate data silos – one inside the firewall and the other outside the firewall. Cloud ISVs oft...
SYS-CON Events announced today that WineSOFT will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Based in Seoul and Irvine, WineSOFT is an innovative software house focusing on internet infrastructure solutions. The venture started as a bootstrap start-up in 2010 by focusing on making the internet faster and more powerful. WineSOFT’s knowledge is based on the expertise of TCP/IP, VPN, SSL, peer-to-peer, mob...
SYS-CON Events announced today that Carbonite will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Carbonite protects your entire IT footprint with the right level of protection for each workload, ensuring lower costs and dependable solutions with DoubleTake and Evault.