Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JBoss AS7 Automatically Loading JPA

I have an application which uses JPA/Hibernate and Google Guice. Guice is bootstrapped in a ServletContextListener and it sets up the EntityManagerFactory itself.

The application works fine on Tomcat 7, but when I deploy to JBoss AS7 it fails because JBoss decides to automatically setup JPA prior to invoking my ServletContextListener.

How can I get JBoss to not initialize JPA automatically and instead wait for my ServletContextListener to do it?

Update

According to the link that James provided below:

During application deployment, JPA use is detected (e.g. persistence.xml or @PersistenceContext/Unit annotations) and injects Hibernate dependencies into the application deployment.

https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide#JPAReferenceGuide-Introduction

I need to figure out how to disable this "auto-detect" feature.

Update #2

Container management of JPA can be disabled by adding the following property to the persistence.xml:

<property name="jboss.as.jpa.managed" value="false" />

According to this topic, as of February 2012 this functionality is only available in a nightly build.

like image 446
Steven Benitez Avatar asked Nov 05 '22 01:11

Steven Benitez


1 Answers

JBoss AS7 is a full Java EE server. That means that a JPA implementation comes bundled with it. In Tomcat you have to provide your own JPA implementation and are essentially running JPA like you would in Java SE.

I would recommend you read the JPA reference documentation for AS7.

You also get CDI so there is no real need for Guice. You could probably use Guice instead of CDI, but honestly I couldn't tell you how :-)

like image 193
James R. Perkins Avatar answered Nov 15 '22 12:11

James R. Perkins