Welcome!

Java IoT Authors: Yeshim Deniz, Elizabeth White, Pat Romanski, Liz McMillan, Chris Schwarz

Related Topics: Java IoT, Open Source Cloud, Apache

Java IoT: Blog Post

Getting Started with OpenJPA

...and everything else around it.

OpenJPA is the open source implementation of the Java Persistence API (JPA). OK, so what's that? THAT is a way to persist information in Java by way of using a back-end database and not having to write a bunch of messy JDBC code. Why is this needed? Well maybe it's not. But unless you are writing calculator software, some output, settings or something has to be saved off. There are plenty of schemes for saving data from writing flat text files, to elegant multi-megabyte XML streams to JDBC connected databases. But JPA is not just another scheme. For Java, it is really THE way to persist data. Why? Because it is the Java way.

During the execution of any interactive code, there is data that is kept. We have vectors and maps and sets and lists of custom classes that we can use to organize and browse information. Such constructs are really custom databases that exist only during program execution. Unless you save that data in some way, the data is lost. But to save it, we have to descend into some very inelegant code where we reformat the information for archiving. The reformatting pre-assumes the nature of the persistence. That means we have to know the JDBC database or we have to design the XML or text format. And then there has to be extra classes that serve no purpose other that to reformat the data. But what if you could add a couple lines of code to your existing data collection managers and the data could be automatically saved away to the database? JPA provides such capability. It's not perfect, of course, but once set up it makes saving data to a database very easy.

So if I haven't lost you by talking about execution time databases and collection managers, then you know what I am talking about and you share my pain. Good. I have written thousands of lines of code to read/write text files, parse DOM trees and transact databases in both ODBC and JDBC. It is never easy and it is never fun. But it's almost always necessary and usually makes an otherwise clean implementation very heavy with messy code. So when I was presented with OpenJPA, I was very interested.

However, when I started looking around for examples or tutorials that spoke in simple terms, all I found was frustration. Once JPA is set up, it's fairly easy to code with it. But knowing what has to be set up and how is the tricky part. Doing it is less tricky if you know what to do but finding that knowledge is not as straight forward as you'd think.

When trying to use a new API, I prefer to see an example of it being used in the simplest of cases. I can then adapt that example for my own use and continue on by referencing the documentation. But JPA is really designed for J2EE applications and that brings in a bunch of complexity. To see what the JPA code does I have to understand what the whole program is doing. Worse, I also have to have a runtime environment that matches the example.  Plan B: just read the specification. Yeah right....OK...plan C?

Well, after much frustration and losing all my spare change by bribing busy associates (who had some experience with JPA) with sodas and coffee, I figured it out. And, because I believe that OpenJPA is worthwhile and I have the discipline to do it, I have put together a couple tutorials that step through setting up and using OpenJPA in excruciating detail.

The first tutorial is a J2EE example. It's not very J2EE-ish because the point is to examine JPA. If you want to try JPA for free and not have to go through a bunch of different installs, this is the one for you. It uses Eclipse, Geronimo, Derby (which is built in to Geronimo) and OpenJPA. They are all free downloads and the tutorial walkes though how to set up and use everything. That's because I hate it when tutorials assume you have something already set up or require you to know something. And as a side benefit, after this you will be introduced to Eclipse, Geronimo, Derby and JSP.

The tutorial is hosted at the Apache OpenJPA website. Just click here. One caveat: the tutorial uses Geronimo 2.2. It looks like the Eclipse plugin for that version is still not generally available. SO, if you are really setting everything up from scratch, use Geronimo 2.1.3 or 2.1.4 instead.

In the interest of disclosure, OpenJPA is just one of many different JPA implementations. But OpenJPA is genuinely open and it is the preferred implementation of WebSphere, which is still the most used J2EE app server.

Go to the tutorial.

More Stories By Scott Quint

Scott Quint has been at IBM since 1996. He's been a developer, Lead Engineer, Chief Engineer, Quality Assurance Lead and Designer, Senior Consultant and Project Manager. Most recently Scott was a Lead Engineer for WebSphere Virtual Enterprise and is now a Cloud Computing Technology Evangelist.

@ThingsExpo Stories
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
"The Striim platform is a full end-to-end streaming integration and analytics platform that is middleware that covers a lot of different use cases," explained Steve Wilkes, Founder and CTO at Striim, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"We provide IoT solutions. We provide the most compatible solutions for many applications. Our solutions are industry agnostic and also protocol agnostic," explained Richard Han, Head of Sales and Marketing and Engineering at Systena America, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that Datera, that offers a radically new data management architecture, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Datera is transforming the traditional datacenter model through modern cloud simplicity. The technology industry is at another major inflection point. The rise of mobile, the Internet of Things, data storage and Big...
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that Calligo, an innovative cloud service provider offering mid-sized companies the highest levels of data privacy and security, has been named "Bronze Sponsor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Calligo offers unparalleled application performance guarantees, commercial flexibility and a personalised support service from its globally located cloud plat...
"We've been engaging with a lot of customers including Panasonic, we've been involved with Cisco and now we're working with the U.S. government - the Department of Homeland Security," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"We are focused on SAP running in the clouds, to make this super easy because we believe in the tremendous value of those powerful worlds - SAP and the cloud," explained Frank Stienhans, CTO of Ocean9, Inc., in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
DX World EXPO, LLC., a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
"MobiDev is a Ukraine-based software development company. We do mobile development, and we're specialists in that. But we do full stack software development for entrepreneurs, for emerging companies, and for enterprise ventures," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
While the focus and objectives of IoT initiatives are many and diverse, they all share a few common attributes, and one of those is the network. Commonly, that network includes the Internet, over which there isn't any real control for performance and availability. Or is there? The current state of the art for Big Data analytics, as applied to network telemetry, offers new opportunities for improving and assuring operational integrity. In his session at @ThingsExpo, Jim Frey, Vice President of S...
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
In his opening keynote at 20th Cloud Expo, Michael Maximilien, Research Scientist, Architect, and Engineer at IBM, discussed the full potential of the cloud and social data requires artificial intelligence. By mixing Cloud Foundry and the rich set of Watson services, IBM's Bluemix is the best cloud operating system for enterprises today, providing rapid development and deployment of applications that can take advantage of the rich catalog of Watson services to help drive insights from the vast t...
SYS-CON Events announced today that EnterpriseTech has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. EnterpriseTech is a professional resource for news and intelligence covering the migration of high-end technologies into the enterprise and business-IT industry, with a special focus on high-tech solutions in new product development, workload management, increased effic...
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and ...
SYS-CON Events announced today that CHEETAH Training & Innovation will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct. 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CHEETAH Training & Innovation is a cloud consulting and IT training firm specializing in improving clients cloud strategies and infrastructures for medium to large companies.
SYS-CON Events announced today that Datanami has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Datanami is a communication channel dedicated to providing insight, analysis and up-to-the-minute information about emerging trends and solutions in Big Data. The publication sheds light on all cutting-edge technologies including networking, storage and applications, and thei...
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...