DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
What's in store for DevOps in 2023? Hear from the experts in our "DZone 2023 Preview: DevOps Edition" on Fri, Jan 27!
Save your seat
  1. DZone
  2. Coding
  3. Java
  4. How to Use JPA and JDO in HBase

How to Use JPA and JDO in HBase

Mitch Pronschinske user avatar by
Mitch Pronschinske
·
Mar. 17, 10 · Interview
Like (0)
Save
Tweet
Share
19.62K Views

Join the DZone community and get the full member experience.

Join For Free
Thanks to Google App Engine's work with DataNucleus, the GAE users have enjoyed JPA and JDO support.  For its storage system, GAE uses the (NoSQL) Google BigTable implementation.  HBase, under the Apache Hadoop project, is a distributed, column-oriented storage system that has been modeled after BigTable.  There are some usage restrictions, but generally it's pretty easy to store data on BigTable using JPA and JDO.  What you may not know is that HBase can also support these standard APIs for a homegrown system.

For developers who don't want to host their applications or store their data at Google, HBase provides a viable (and Apache community supported) option for building your own open source system.  JDO and JPA are also used through DataNucleus to persist objects in HBase.  To install HBase, just read the documentation, which covers all of the possible pitfalls.  Set up is not very difficult.  Next, Matthias Wessendorf explains how to use the JPA with HBase.  You start with a regular persistence XML file listing your classes and the actual configuration:
<persistence...>
<persistence-unit...>

<class>net.wessendorf...</class>
...

<properties>
<property name="datanucleus.ConnectionURL" value="hbase"/>
<property name="datanucleus.ConnectionUserName" value=""/>
<property name="datanucleus.ConnectionPassword" value=""/>
<property name="datanucleus.autoCreateSchema" value="true"/>
<property name="datanucleus.validateTables" value="false"/>
<property name="datanucleus.Optimistic" value="false"/>
<property name="datanucleus.validateConstraints" value="false"/>
</properties>

</persistence-unit>
</persistence>
In most cases you'll want to add @Entity to your class and try to deal with any limitations.  When your data model is complete, you can, for example, start using the EntityManager natively:
EntityManagerFactory emf = Persistence.createEntityManagerFactory(...);
EntityManager entityManager = emf.createEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();

entityManager.persist(myJPAentity);

entityTransaction.commit();
More often, you may instead want to move the JPA-dealing code into a DataAccessObject.  

During a Maven build (shown below) you'll have to enhance the bytecode of the actual classes.  Lucky for you, DataNucleus offers a Maven plugin:
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>maven-datanucleus-plugin</artifactId>
<version>2.0.0-release</version>
<configuration>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
<api>JPA</api>
<persistenceUnitName>nameOfyourPU</persistenceUnitName>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
                                             

There are significant benefits in this method when hosting a normal Java EE application on HBase.  Because Java EE uses the JPA for most of its storage, the integration of JEE applications is a lot easier.  You can also use the 'native' HBase API to read and store data on a JPA/JDO managed HBase table, but the code is not as simple.
Java Data Objects

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A Guide To Successful DevOps in Web3
  • The Future of Cloud Engineering Evolves
  • Top Five Tools for AI-based Test Automation
  • Type Variance in Java and Kotlin

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: