JBoss 5.1: Hibernate with JPA
Asked Answered
H

2

6

I've got two questions to ask regarding JBoss 5.1. We are in process of migrating from JBoss 4.2 to JBoss 5.1.

We are also using Java 1.6 and JPA 2.0 with Hibernate 3.6 as the provider.

My questions are:

  1. Is it possible to use Hibernate 3.6+ with JBoss 5.1. If yes, then how?
  2. What about JPA 2.0? I know that JBoss 5.1 comes with JPA 1.0 compatibility. Can we use JPA2?

And as we can not do any kind of configuration to the JBoss installation, all the fixes need to be done in our application only.

Thanks in advance, JassB

Hughes answered 13/4, 2012 at 11:44 Comment(0)
A
2

Do this:

1) Add jboss-classloading.xml to /src/main/webapp (I am using Maven):

content:

<?xml version="1.0" encoding="UTF-8"?>

<classloading xmlns="urn:jboss:classloading:1.0"

         domain="$UNIQUE_DOMAIN_NAME"

         export-all="NON_EMPTY"

         import-all="false"

         parent-first="false">

</classloading>

2) Modify $JBOSS_INSTALL_DIRECTORY/jboss-as/server/$PROFILE/conf/bootstrap/deployers.xml, and add the following at the end:

<bean name="IgnoreFilesDeployer"

class="org.jboss.deployers.vfs.spi.deployer.AbstractIgnoreFilesDeployer"



</bean>

3) Create a file JBOSS-IGNORE.TXT in the META-INF folder with following content:

WEB-INF/classes/META-INF/persistence.xml

4) I've renamed my persistence.xml to spring-persistence.xml and added this file in the context.xml as:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="persistenceXmlLocation" value="classpath:/META-INF/spring-persistence.xml"/>
           ....
</bean>

5) I;ve also modified the spring-persistence.xml (saved persistence_2_0.xsd in webapp\META-INF folder) as

 <persistence version="2.0"
 xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="file:///persistence_2_0.xsd 
        http://java.sun.com/xml/ns/persistence">
....
</persistence>
Alienist answered 25/4, 2012 at 8:45 Comment(1)
Following this I get a ClassNotFoundException about rg.jboss.webbeans.integration.deployer.env.WebBeansBootstrapDeployer which is quite weird, because it is a class included on jBoss 5.1.Carbine
S
3

I just got the same problem today, and after trying many alternatives and asking everywhere, the answer is no

You cannot use JPA 2.0 with Jboss 5.1 (even more if you cannot change the server's configuration)

But I've seen hibernate3.X working on Jboss5.1, but never with the annotations features : only the old XML configuration way.

Now, in my point of view, you've got 2 solutions : either asking for server upgrades or changing your data acess system with the old fashion.

Surgeon answered 17/4, 2012 at 18:5 Comment(2)
Was someone able to figure out how to actually integrate JPA 2.0 or is this answer incorrect?Reduplication
In my case, the server was upgraded in production since then : no more problems !Surgeon
A
2

Do this:

1) Add jboss-classloading.xml to /src/main/webapp (I am using Maven):

content:

<?xml version="1.0" encoding="UTF-8"?>

<classloading xmlns="urn:jboss:classloading:1.0"

         domain="$UNIQUE_DOMAIN_NAME"

         export-all="NON_EMPTY"

         import-all="false"

         parent-first="false">

</classloading>

2) Modify $JBOSS_INSTALL_DIRECTORY/jboss-as/server/$PROFILE/conf/bootstrap/deployers.xml, and add the following at the end:

<bean name="IgnoreFilesDeployer"

class="org.jboss.deployers.vfs.spi.deployer.AbstractIgnoreFilesDeployer"



</bean>

3) Create a file JBOSS-IGNORE.TXT in the META-INF folder with following content:

WEB-INF/classes/META-INF/persistence.xml

4) I've renamed my persistence.xml to spring-persistence.xml and added this file in the context.xml as:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="persistenceXmlLocation" value="classpath:/META-INF/spring-persistence.xml"/>
           ....
</bean>

5) I;ve also modified the spring-persistence.xml (saved persistence_2_0.xsd in webapp\META-INF folder) as

 <persistence version="2.0"
 xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="file:///persistence_2_0.xsd 
        http://java.sun.com/xml/ns/persistence">
....
</persistence>
Alienist answered 25/4, 2012 at 8:45 Comment(1)
Following this I get a ClassNotFoundException about rg.jboss.webbeans.integration.deployer.env.WebBeansBootstrapDeployer which is quite weird, because it is a class included on jBoss 5.1.Carbine

© 2022 - 2024 — McMap. All rights reserved.