Welcome!

Java IoT Authors: Liz McMillan, Elizabeth White, Pat Romanski, William Schmarzo, Stackify Blog

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
SYS-CON Events announced today that MIRAI Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. MIRAI Inc. are IT consultants from the public sector whose mission is to solve social issues by technology and innovation and to create a meaningful future for people.
SYS-CON Events announced today that Fusic will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Fusic Co. provides mocks as virtual IoT devices. You can customize mocks, and get any amount of data at any time in your test. For more information, visit https://fusic.co.jp/english/.
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
SYS-CON Events announced today that Taica will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Taica manufacturers Alpha-GEL brand silicone components and materials, which maintain outstanding performance over a wide temperature range -40C to +200C. For more information, visit http://www.taica.co.jp/english/.
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant th...
In his session at @ThingsExpo, Greg Gorman is the Director, IoT Developer Ecosystem, Watson IoT, will provide a short tutorial on Node-RED, a Node.js-based programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using a wide range of nodes in the palette that can be deployed to its runtime in a single-click. There is a large library of contributed nodes that help so...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Daiya Industry specializes in orthotic support systems and assistive devices with pneumatic artificial muscles in order to contribute to an extended healthy life expectancy. For more information, please visit https://www.daiyak...
What is the best strategy for selecting the right offshore company for your business? In his session at 21st Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, will discuss the things to look for - positive and negative - in evaluating your options. He will also discuss how to maximize productivity with your offshore developers. Before you start your search, clearly understand your business needs and how that impacts software choices.
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
SYS-CON Events announced today that Yuasa System will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Yuasa System is introducing a multi-purpose endurance testing system for flexible displays, OLED devices, flexible substrates, flat cables, and films in smartphones, wearables, automobiles, and healthcare.
SYS-CON Events announced today that B2Cloud 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. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.
SYS-CON Events announced today that NetApp 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. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
SYS-CON Events announced today that Ryobi Systems will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
SYS-CON Events announced today that mruby Forum will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. mruby is the lightweight implementation of the Ruby language. We introduce mruby and the mruby IoT framework that enhances development productivity. For more information, visit http://forum.mruby.org/.
SYS-CON Events announced today that Mobile Create USA will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Mobile Create USA Inc. is an MVNO-based business model that uses portable communication devices and cellular-based infrastructure in the development, sales, operation and mobile communications systems incorporating GPS capabi...
SYS-CON Events announced today that Enroute Lab will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Enroute Lab is an industrial design, research and development company of unmanned robotic vehicle system. For more information, please visit http://elab.co.jp/.
Real IoT production deployments running at scale are collecting sensor data from hundreds / thousands / millions of devices. The goal is to take business-critical actions on the real-time data and find insights from stored datasets. In his session at @ThingsExpo, John Walicki, Watson IoT Developer Advocate at IBM Cloud, will provide a fast-paced developer journey that follows the IoT sensor data from generation, to edge gateway, to edge analytics, to encryption, to the IBM Bluemix cloud, to Wa...
SYS-CON Events announced today that Nihon Micron will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Nihon Micron Co., Ltd. strives for technological innovation to establish high-density, high-precision processing technology for providing printed circuit board and metal mount RFID tags used for communication devices. For more inf...
SYS-CON Events announced today that Suzuki Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Suzuki Inc. is a semiconductor-related business, including sales of consuming parts, parts repair, and maintenance for semiconductor manufacturing machines, etc. It is also a health care business providing experimental research for...
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...