Showing posts with label JPA. Show all posts
Showing posts with label JPA. Show all posts

Friday, March 15, 2013

EJB Lite feature supports JPA in Liberty Beta

The WebSphere V8.5.Next Liberty Profile Alpha gave us a first look at a new EJB Lite (ejblite-3.1) feature for the WebSphere Liberty profile.  If you use EJB session beans to drive your persistence layer you may have been disappointed since the EJB Lite capability in the Alpha didn't include support for JEE-style use of JPA with EJBs.  Attempts at injecting or lookup of JPA entity managers and/or factories within an EJB resulted in an exception.  The use of JPA with Java SE style bootstrapping (Persistence.createEntityManagerFactory()) may have worked if you happened to be using resource local transactions and connection properties (rather than server defined data sources).  This was not an ideal or typical configuration in the application server environment.

But, enough about the Alpha!  I'm happy to report that the recent WebSphere V8.5.Next Liberty Profile Beta includes a major bump in EJB Lite functionality, including integration with JPA.  This integration includes all you might expect, container managed persistence, enlistment in JTA transactions, and support for extended persistence contexts.  The WebSphere Development Tools for Eclipse Beta 9 on top of Eclipse WTP makes it a piece of cake to create new or modify existing EJB and JPA applications.  To enable EJB and JPA in the Liberty Beta just add this feature set to your server.xml (include any other features you may require):
  <featuremanager>
    <feature>ejblite-3.1</feature>
    <feature>jpa-2.0</feature>
  </featuremanager>

Check it out!

-Jeremy

Wednesday, May 9, 2012

OpenBooks sample works with new WebSphere Liberty Profile!

There is an exciting new feature in WebSphere Application Server v8.5 called the Liberty Profile.  The Liberty Profile provides a new, sleek, highly-efficient application server environment both for development and production use.  You can find out more details about Liberty on WASdev Home.

For those of you that joined me at Impact 2012 last week, I mentioned in my JPA presentation that I had attempted to deploy OpenBooks to a Liberty Profile server on the plane to Vegas.  With just a couple of modifications to my configuration, I was able to get OpenBooks up and running in no time.  But, I needed to update the OpenBooks instructions before going "public" with the information.

I have now completed the updates to the OpenBooks sample and associated instructions.  In addition to making the necessary configuration updates to run the OpenBooks application on Liberty, I also updated a few other build, install, and execution issues.  You can now build and execute the OpenBooks sample in JSE mode and two JEE environments -- WebSphere Application Server, and the new Liberty Profile.  Enjoy!

Wednesday, July 7, 2010

Using Bean Validation with the OSGi/JPA 2.0 Feature Pack

Do you have applications littered with layers of inconsistent validation logic or are writing a new application that will require data validation? Bean validation (JSR-303 - part of the Java EE6 family of specifications) defines an API for providing runtime validation of data within Java beans. In addition, other EE6 specifications such as JPA 2.0, JSF, and JCA provide tight integration with bean validation, allowing runtime validation to occur seemlessly with your persistence, resource/connectivity, and UI logic.

Using bean validation within the app server requires a JSR-303 spec API library, the bean validation provider library(ies), and any supporting libraries. If you'd like to test drive bean validation with JPA 2.0, the
WebSphere Application Server V7 Feature Pack for OSGi Applications and Java Persistence API 2.0 does not include a bean validation API or provider, but it does include a provision for wiring one in yourself. The wiring is pretty simple and is briefly explained in this IBM Infocenter document Using Bean Validation with JPA. With the information provided in the article, I was able to configure WebSphere Application Server to use Apache's Bean Validation provider using these steps.
  1. Install WebSphere Application Server V7 with the Fixpack required for the feature pack (currently 7.0.0.9). There is a free Developer's Edition if you don't have the V7 test server for RAD 7.5 or an extra license lying about. :-)
  2. Install the WebSphere Application Server V7 Feature Pack for OSGi Applications and Java Persistence API 2.0.
  3. Download the Apache Bean Validation Spec API jar. Save to a location such as:
    /opt/apache/specs/geronimo-validation_1.0_spec-1.1.jar
  4. Download the Apache Bean Validation Core jar. Save to a location such as:
    /opt/apache/bval/bval-core-0.1-incubating.jar
  5. Download the Apache Bean Valdation JSR-303 jar. Save to a location such as:
    /opt/apache/bval/bval-jsr303-0.1-incubating.jar
  6. Download Apache Commons Bean Utils. Extract the distribution and locate commons-beanutils-1.8.3.jar. Copy the jar to a location such as:
    /opt/apache/commons/commons-beanutils-1.8.3.jar
  7. Download Apache Commons Lang 2.4. Extract the distribution and locate commons-lang-2.4.jar. Copy the jar to a location such as:
    /opt/apache/commons/commons-lang-2.4.jar
  8. Start the app server.
  9. Open the WebSphere Integrated Solutions Console in your browser (http://<server:port>/admin).
  10. In the navigation pane expand Servers -> Server Types and click on WebSphere application servers.
  11. Select the server profile to configure. Typically server1 in a default single server environment.
  12. Under the Server Infrastructure section, select Process Definition.
  13. Under the Additional Properties section, select Java Virtual Machine.
  14. Under the Additional Properties section of the JVM settings, select Custom properties.
  15. Click New and add a property named com.ibm.websphere.validation.api.jar.path and set the value to the location of the bean validation API jar. (ex. /opt/apache/specs/geronimo-validation_1.0_spec-1.1.jar)
  16. Restart the application server.

The application server is now configured to locate and load the bean validation spec API jar. The spec API classes are now available, but the application server (being an EE5 app server) does include a bean validation provider. You need to make a provider available to your application by either bundling it with your application archive (in the proper location within a war or ear) or via a shared library. Include the bean validation core, bean validation jsr-303 component, commons bean utils, and commons lang 2.4 jars within the application or shared library and you'll be off to the races.

That's all there is to configuring the application server. To actually build applications which take advantage of bean validation constraints, you'll need to specify the spec API library in the build path of your tooling. The examples in Apache Bean Validation Primer will help you get started. The example in the primer is targeted for a JSE environment (I'm working on a JEE version -- no ETA), but the JPA entities, constraints, validators, and logic can be easily ported to an EE environment. One additional very important item to note is that your persistence.xml must be updated to version 2.0 in order for bean validation to be enabled by the JPA provider (OpenJPA). Since the 2.0 schema is backward compatible, it is typically a simple one line XML change. The JPA Integration section of the primer contains the rationale for this requirement and an example.

-Jeremy

Monday, April 26, 2010

Apache OpenJPA 2.0.0 Now Available!

I am proud to announce the availability of Apache OpenJPA 2.0.0!

This distribution is based on the final JSR 317 Java Persistence API, Version 2.0 specification and passes the JPA 2.0 TCK, while remaining backwards compatible with prior releases based on the Java Persistence API (JPA 1.0) part of Java Community Process JSR-220 (Enterprise JavaBeans 3.0).

The WebSphere JPA solution is based on the Apache OpenJPA project.

Check it out!

Kevin

Thursday, March 4, 2010

Beta 2 of Apache OpenJPA now available!

As we continue to march towards a 2.0.0 release of OpenJPA, we recently announced a Beta 2 of the OpenJPA 2.0.0 deliverable. This release contains additional bug fixes and performance improvements in addition to continuing our TCK compliance.

Enjoy! Let us know your views and comments either via this forum or the OpenJPA mailing lists.

Thanks,
Kevin

Friday, February 12, 2010

WebSphere V7 Feature Pack for OSGi Applications and Java Persistence API (JPA) 2.0 Open Beta now Available!

I actually have two announcements to make. From a WebSphere perspective, I am pleased to announce the availability of the IBM WebSphere Application Server V7 Feature Pack for OSGi Applications and Java Persistence API (JPA) 2.0 Open Beta.

I know that's a mouth full, but this announcement clearly demonstrates IBM's commitment to both the OSGi and JPA programming models. Each of these features can be individually installed on a WebSphere v7 system (specifically, 7.0.0.7). More details on the specifics can be found on the official announcement page above.

The other item I would like to announce is the availability of the Apache OpenJPA 2.0.0-beta release. This beta release is 100% compatible with the JPA 2.0 TCK, plus it contains several other improvements outlined on the announcement. This OpenJPA 2.0.0-beta has been available for a couple of weeks, but I was waiting to announce it in conjunction with the WebSphere Open Beta. (Apache OpenJPA provides the basis for the WebSphere JPA solution.)

So, whether you are a WebSphere customer or just interested in experimenting with the latest JPA 2.0 feature set, one of these two offerings should fit the bill. Enjoy!

Thursday, October 29, 2009

WebSphere JPA 2.0 Open Alpha is now available!

Hi,
The WebSphere JPA team is proud to announce the availability of the IBM WebSphere Application Server V7 Java Persistence API (JPA) 2.0 Open Alpha. Details can be found here...

https://www14.software.ibm.com/iwm/web/cc/earlyprograms/websphere/wsasjpaoa/

This JPA 2.0 Open Alpha is based off the Public Final Draft #2 of the JPA 2.0 specification, which can be found here...

http://jcp.org/en/jsr/detail?id=317

If you are looking for something a bit more readable that highlights the new JPA 2.0 features, you could also reference the following two articles...

http://www.ibm.com/developerworks/websphere/techjournal/0909_col_sutter/0909_col_sutter.html
http://www.ibm.com/developerworks/java/library/j-typesafejpa/

Since the WebSphere JPA solution is built on top of the Apache OpenJPA project, you can always follow our progress via these URLs...

http://openjpa.apache.org/
http://openjpa.apache.org/jpa-20-roadmap.html

Enjoy!
Kevin

Thursday, June 25, 2009

OpenJPA with solidDB

Donald Vines and myself recently published a DeveloperWorks article on how to use solidDB with OpenJPA. In a nutshell, since solidDB is a JDBC-compliant in-memory database, this configuration just worked out-of-the-box with the generic JDBC dictionary provided by OpenJPA. It still is on our wish list to create a specific dictionary for solidDB, but in the mean time, this article shows that the integration of solidDB and OpenJPA is possible today.

http://www.ibm.com/developerworks/websphere/techjournal/0906_vines/0906_vines.html

Enjoy!
Kevin

Thursday, January 22, 2009

JPA Connection Pooling

OpenJPA does not use any kind of connection pooling out of the box, but no worries for those of you using openJPA on WebSphere. When running on WebSphere, the application server provides production-quality connection pooling. That is great if your application runs on WAS, not so great otherwise. Since I haven't found a *good* reason why anyone would run without connection pooling, it seems like a good topic for a first post.

Modifying an existing application to use connection pooling couldn't be easier. To start, you're going to need to download the Apache Commons Pool and DBCP components and add them to your application classpath. Next you will need to update the application database connection properties. Below is an example openJPA configuration using DBCP. You will need to update the connection info where appropriate if using a different DB. Note that these properties are being set in the META-INF/persistence.xml file, but you can also set the JVM system properties directly.

<property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
<property name="openjpa.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/test,Username=root,Password=password"/>
Configuring openJPA to use connection pooling is as simple as that. I created a small JSE application for this post that uses both pooled and non-pooled connections to do 1000 selects on an empty table. Even though the example is very simple, the results are pretty impressive.
  • 1000 selects with no connection pooling took ~23.469 seconds.
  • 1000 selects with connection pooling took ~1.234 seconds.
-Rick