0

I have a Dynamic Web Application that access a DB2 v10 zOS Database.

I wish to use Hibernate 5 as my JPA 2.1 Provider and access my EntityManager via CDI.

I do not want to use the Spring Framework at all; I also do not wish to have a web.xml file.

How can I configure my persistence context and persistence unit WITHOUT using web.xml when deploying my application to WebSphere Application Server Liberty v9 Beta?

Jawher
  • 6,937
  • 1
  • 17
  • 12
Hector
  • 4,016
  • 21
  • 112
  • 211
  • 1
    What have you tried so far? What worked and what didn't work? (What do you mean specifically by "dynamic web application"?) – Brett Kail Nov 22 '15 at 16:32
  • 1
    @bkail "dynamic web application" is referring to the type of project you create in an eclipse environment – Andy Guibert Nov 22 '15 at 17:15
  • @bkail i have tried defining the datasource in the server.xml and using a persistetnce.xml, the "injected" EntityManager" is always null though. – Hector Nov 22 '15 at 20:28
  • You probably need to add an Resource annotation on a Servlet class. I've managed to get JPA and Servlet working this way, but you need a resource reference and Resource on a servlet will do that for you. You should specify the name on Resource in common with what is in persistence.xml. – Alasdair Nov 23 '15 at 20:43
  • Do you have jpa-2.1 and cdi-1.2 features enabled? What is the data source JNDI name that you use in the `persistence.xml`? Do you have `` element defined in it? But I'd suggest to stick with default EclipseLink provider. – Gas Nov 23 '15 at 21:15
  • i have all required features enabled. the jndi data asource is setup and i have defined. I do not like EclipseLink provider, I wish to use Hibernate 5 – Hector Nov 24 '15 at 04:38

1 Answers1

1

The first result on google for "websphere liberty hibernate" gave me the link to a sample app that uses Liberty with Hibernate.

WASdev Liberty + Hibernate sample

Note that the jpaApp.war DOES use a web.xml, but this can easily be avoided by using the proper @WebServlet annotation and changing the persistence.xml to point to a server-defined datasource instead of a component-defined datasource.

@WebServlet(displayName="JPA Servlet", urlPatterns="/JPAServlet")
public class JPAServlet extends HttpServlet {
    // ...
}
Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
  • That sample app is JPA 2.0 and uses a web.xml. My question relates to Liberty, JPA 2.1, and WITHOUT web.xml. I believe i can still define my data source (with jndi name) in the liberty server.xml, i need to know how to define the persistence context and entity manager without using web.xml. I should have been clearer my dynamic web app is JAXRS I do not want any mention of (AT)WebServlet or extend HttpServlet. – Hector Nov 22 '15 at 20:15
  • @Hector, you should still be able to use a lot of the sample. Just update server.xml to have the `jpa-2.1` feature, user newer hibernate libs. I also believe you can use the `@PersistenceContext` annotation to avoid needing to specify `` in the web.xml as well. – Andy Guibert Nov 22 '15 at 21:47