Override JPA of IBM WAS - java

I am using JPA 2.1 in my project (Hibernate 5.x) and deploying in IBM WAS 8.5.5.
Since IBM WAS 8.5.5 supports only JPA 2.0 by the container, There is persistence loader issue during application deployment.
Is it possible to configure custom JPA at app level in WAS.
I already tried - IBM WAS Documentation

You said you tried https://developer.ibm.com/wasdev/docs/can-i-use-jpa-2-1-on-websphere-application-server/, but what part of this document is not working? This is the page I would reference if you are trying to get JPA 2.1 running on 8.5.5.
Some alternate suggestions:
Traditional WebSphere v9 supports the JPA 2.1 specification level. I would recommend using WebSphere v9 for your project instead of 8.5.5 if you really need to use Hibernate 5.x
Hibernate 4.2 was the last version that supports JPA 2.0. You can downgrade to this version of Hibernate if you dont have to use JPA 2.1
Either of these solutions gain you container support and will provide the JPA API bundle for you. Whichever you go with, make sure not to bundle your Hibernate JPA persistence API bundles in your application. Hibernate repackages its API into "hibernate-jpa-2.x-api.Final.jar". I have seen this before as a conflict that customers build into their applications.

With class loading strategy, I was able to override the JPA 2.0 of container.
using the inputs from IBM Developers support.

Related

Spring 3.0.3 and JMS 2.0 Support

I am upgrading my application's JMS from 1.1 to 2.0.
My application is currently having Spring 3.0.3 and uses JMSTemplete.
Is there any official ( Spring or JMS ) documentation mentioning the support for JMS 2.0 with Spring 3.0.3?
I was actually searching it in order to find out weather any Spring related change is required in my application or not.
It should just work since the 1.1 APIs are still supported in 2.0.
If you want to use the new 2.0 shared subscription feature (on topics), you will need to upgrade to at least Spring 4.1.

Is it possible to configure JBoss EAP 6.4.x for Spring 4 and Hibernate 4.3.10 using JPA 2.1 by configuring it over jboss-deployment-structure.xml?

We recently switched to Java 8 to use java.time API (LocalDate, LocalDateTime,...). Therefore we updated our Hibernate dependency to version 4.3.10. We wrote some AttributeConverters to help Hibernate to map new Java 8 classes to the database.
e.g.
#Converter(autoApply = true)
public class LocalDateConverter implements AttributeConverter<LocalDate, Date>
To use javax.persistence.Converter and javax.persistence.AttributeConverter we had to update Hibernate to 4.3.10 to work with JPA 2.1. But JBoss EAP 6.4.x does not support JPA 2.1 and comes along with JPA 2.0. Therefore, we get some deployment errors. How can we get our JPA 2.1 application running on JBoss!?
Should we downgrade Hibernate to a Hibernate version lower than 4.3.10 to work with JPA 2.0?
Or is there a nice way to exclude JPA 2.0 using the jboss-deployment-structure.xml?
You are mixing up Java8/JDK8 with JEE7 specification. JBoss EAP 6.4 is a JEE6 container. JEE6 requires JPA 2.0 which is why you have JPA 2.0 implementation in JBoss EAP 6.4. Once JBoss releases a JEE7 implemented container, you should be able to use JPA 2.1 there.
It should be fine to use JBoss EAP 6.4 running on JDK8.
I would not recommend modifying the hibernate jars or manually including JPA 2.1 jars. There are other aspects of JPA for example the secondary cache which is implemented by Infinispan in JBoss might not have been tested with JPA 2.1 cache stores.
If you really need to utilize a JEE7 JBoss container, then take a look at WilFLy 9. However, this is a community build, so it is not supported.

Do i need JPA provider (like Hibernate) if i am using EJB?

i am reading book about EJB 3.l, and they are talking about Enities and EntityManager, but i cant see any Hibernate(or other ORM framework) configuration. Does EJB has its own ORM and JPA support ?
EJB and JPA are two different specifications that are part of the Java EE standard. You can use either of them without using the other.
EDIT: EJB is used within Java EE compliant servers like WildFly (formerly known as JBoss) and Glassfish. IF you are using one, you always have an implementation of JPA on board.
JPA on the other hand is not bound to such a server and can be used in servlet containers like Tomcat and standalone Java SE applications.
JPA can be used outside the container like with RESTful WS. While EJB resides in containers like WebLogic, Tomcat, etc.
In a way, JPA is a lighter version of EJB. Try googling JPA vs EJB3

Hibernate Validator 5 version compatibility with Hibernate 3.5

Is it safe to use the Hibernate Validator 5.0.1 with Hibernate 3.5.4? From what I've read it should not be a problem and I'm not running into any errors so far (i.e. application compiles, runs and tests pass), but I'm not sure if they fit well together.
Related Hibernate & JPA libs (inside /WEB-INF/libs):
hibernate3.jar
hibernate-annotations-3.5.4-Final.jar
hibernate-commons-annotations-3.2.0.Final.jar
hibernate-core-3.5.4-Final.jar
hibernate-entitymanager-3.5.4-Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-validator-5.0.1.Final.jar
hibernate-validator-annotation-processor-5.0.1.Final.jar
validation-api-1.1.0.Final.jar
FYI:
Tomcat 7.0.39
Spring 3.0.3
PostgreSQL 9.2
Flyway 2.1.1
BoneCP 0.7.1
You should be fine with using Bean Validation 1.1/Hibernate Validator 5.0.1; Hibernate ORM depends on the Bean Validation API only, and BV 1.1 is compatible with BV 1.0.
I recommend to check the Hibernate Validator migration guide to see whether any of the issues listed there might affect you (for instances changes around logging and the usage of Java 6).

Should you default to the JPA provider of the application server?

I have a 100% JPA2 compliant application which needs to be portable to many application servers. Being JPA compliant (theoretically) means we can switch JPA providers via configuration (e.g. without changing source code) -- (right???).
When running within a servlet container (e.g. Tomcat, Jetty) the application is configured to run with Hibernate. We choose Hibernate over TopLink and Eclipselink for its maturity and performance. So far this works.
However, when running within a Java EE application server, should we default to the JPA provider therein, or stick with Hibernate?
I know within JBoss, the provider is Hibernate so it probably doesn't matter. However, I think the provider within WebLogic is Eclipselink. I have no idea what the provider WebSphere or Glassfish use, but I have seen detailed instructions on how to use Hibernate as the provider within those application servers.
I guess another way to ask the question is what would we be missing by using Hibernate in these application servers?
I have a 100% JPA2 compliant application which needs to be portable to many application servers. Being JPA compliant (...) means we can switch JPA providers via configuration (...)
Yes.
(...) However, when running within a Java EE application server, should we default to the JPA provider therein, or stick with Hibernate?
Well, if you deploy on a Java EE 6 server, this doesn't really matter. It's not clear who is going to run the application and you can maybe make recommendations but the runtime is actually "not your business" :) Also note that you may not benefit from support if you don't use the default provider (if this matters).
I know within JBoss, the provider is Hibernate so it probably doesn't matter. However, I think the provider within WebLogic is Eclipselink. I have no idea what the provider WebSphere or Glassfish use, but I have seen detailed instructions on how to use Hibernate as the provider within those application servers.
First of all, keep in mind that JPA 2.0 is part of Java EE 6 and that GlassFish v3 is the only one Java EE 6 container at this time. WebLogic and WebSphere are Java EE 5 server, they may not support JPA 2.0.
Now, regarding the default providers:
GlassFish v3 uses EclipseLink 2.0 as default provider but can be configured to use Hibernate 3.5 (through an add-on).
In Weblogic 10.3.2, the default JPA provider is OpenJPA/Kodo and EclipseLink 1.2 is available as a WLS module. In WLS 10.3.3 (not released yet), EclipseLink 2.0 will be available as a WLS module, the default being still OpenJPA/Kodo. But, the container JPA API will still be JPA 1.0! It seems possible to package a JPA 2.0 provider inside your application. See this thread and this page. But this is not officially supported and doing this same thing with Hibernate 3.5 might be another story.
In WebSphere 6 and 7, the default provider is OpenJPA. This link will give you some details about the way to change the default provider (and the consequences). But I can't tell you more.
I guess another way to ask the question is what would we be missing by using Hibernate in these application servers?
As I mentioned, this may not be supported by the vendor. Additionally, if you want to maximize portability and plan to deploy your application in a near future, going for JPA 2.0 is maybe not a wise choice (or too optimistic if you prefer).
I don't see what you will be missing, unless you're using implementation specific API in your JPA code. I.e. do not import org.hibernate anywhere in your JPA code, but just write it against the JPA API.

Categories

Resources