...
Replace the content of pom.xml
which is the main configuration file of any maven project to the following:
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.apache.geronimo.hibernate.transaction</groupId> <artifactId>geronimo-hibernate-transaction-manager-lookup</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>geronimo-hibernate-transaction-manager-lookup</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jta_1.1_spec</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>3.2.5.ga</version> <exclusions> <exclusion> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.geronimo.framework</groupId> <artifactId>geronimo-kernel</artifactId> <version>2.1.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> </project> |
...
Create the org.apache.geronimo.hibernate.transaction.GeronimoTransactionManagerLookup
class in src/main/java/org/apache/geronimo/hibernate/transaction/
directory.
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
package org.apache.geronimo.hibernate.transaction; import java.util.Properties; import java.util.Set; import javax.transaction.TransactionManager; import org.apache.geronimo.gbean.AbstractName; import org.apache.geronimo.gbean.AbstractNameQuery; import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.KernelRegistry; import org.hibernate.HibernateException; import org.hibernate.transaction.TransactionManagerLookup; public class GeronimoTransactionManagerLookup implements TransactionManagerLookup { public static final String UserTransactionName = "java:comp/UserTransaction"; public TransactionManager getTransactionManager(Properties props) throws HibernateException { try { Kernel kernel = KernelRegistry.getSingleKernel(); AbstractNameQuery query = new AbstractNameQuery(TransactionManager.class.getName ()); Set<AbstractName> names = kernel.listGBeans(query); if (names.size() != 1) { throw new IllegalStateException("Expected one transaction manager, not " + names.size()); } AbstractName name = names.iterator().next(); TransactionManager transMg = (TransactionManager) kernel.getGBean(name); return (TransactionManager)transMg; } catch (Exception e) { e.printStackTrace(); System.out.println(); throw new HibernateException("Geronimo Transaction Manager Lookup Failed", e); } } public String getUserTransactionName() { return UserTransactionName; } } |
...
If you tried to deploy JBoss Seam's booking application with Hibernate JPA as it is now it would choke with NPE.
No Format | borderStyle | solid|||
---|---|---|---|---|
| ||||
12:10:24,359 INFO [Version] Hibernate Annotations 3.3.0.GA 12:10:24,437 INFO [Environment] Hibernate 3.2.4.sp1 12:10:24,734 INFO [Environment] hibernate.properties not found 12:10:24,734 INFO [Environment] Bytecode provider name : cglib 12:10:24,750 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling 12:10:25,171 INFO [Version] Hibernate EntityManager 3.3.1.GA 12:10:25,328 INFO [Ejb3Configuration] Processing PersistenceUnitInfo [ name: bookingDatabase ...] 12:10:25,328 ERROR [GBeanInstanceState] Error while starting; GBean is now in the FAILED state: abstractName="org.jboss.seam.examples.jee5/jboss-seam-jee5/2.0.0.GA/ear?EJBModule=jboss-s eam-jee5.jar,J2EEApplication=org.jboss.seam.examples.jee5/jboss-seam-jee5/2.0.0.GA/ear,PersistenceUnitModule=jboss-seam-jee5.jar,j2eeType=PersistenceUnit,name=bookingDatabase" java.lang.NullPointerException at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:346) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126) at org.apache.geronimo.persistence.PersistenceUnitGBean.<init>(PersistenceUnitGBean.java:117) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at org.apache.geronimo.gbean.runtime.GBeanInstance.createInstance(GBeanInstance.java:946) at org.apache.geronimo.gbean.runtime.GBeanInstanceState.attemptFullStart(GBeanInstanceState.java:268) at org.apache.geronimo.gbean.runtime.GBeanInstanceState.start(GBeanInstanceState.java:102) at org.apache.geronimo.gbean.runtime.GBeanInstance.start(GBeanInstance.java:539) at org.apache.geronimo.gbean.runtime.GBeanDependency.attemptFullStart(GBeanDependency.java:111) at org.apache.geronimo.gbean.runtime.GBeanDependency.addTarget(GBeanDependency.java:146) at org.apache.geronimo.gbean.runtime.GBeanDependency$1.running(GBeanDependency.java:120) at org.apache.geronimo.kernel.basic.BasicLifecycleMonitor.fireRunningEvent(BasicLifecycleMonitor.java:176) at org.apache.geronimo.kernel.basic.BasicLifecycleMonitor.access$300(BasicLifecycleMonitor.java:44) at org.apache.geronimo.kernel.basic.BasicLifecycleMonitor$RawLifecycleBroadcaster.fireRunningEvent(BasicLifecycleMonitor.java:254) at org.apache.geronimo.gbean.runtime.GBeanInstanceState.attemptFullStart(GBeanInstanceState.java:294) at org.apache.geronimo.gbean.runtime.GBeanInstanceState.start(GBeanInstanceState.java:102) at org.apache.geronimo.gbean.runtime.GBeanInstance.start(GBeanInstance.java:539) at org.apache.geronimo.gbean.runtime.GBeanDependency.attemptFullStart(GBeanDependency.java:111) at org.apache.geronimo.gbean.runtime.GBeanDependency.addTarget(GBeanDependency.java:146) at org.apache.geronimo.gbean.runtime.GBeanDependency$1.running(GBeanDependency.java:120) at org.apache.geronimo.kernel.basic.BasicLifecycleMonitor.fireRunningEvent(BasicLifecycleMonitor.java:176) at org.apache.geronimo.kernel.basic.BasicLifecycleMonitor.access$300(BasicLifecycleMonitor.java:44) at org.apache.geronimo.kernel.basic.BasicLifecycleMonitor$RawLifecycleBroadcaster.fireRunningEvent(BasicLifecycleMonitor.java:254) at org.apache.geronimo.gbean.runtime.GBeanInstanceState.attemptFullStart(GBeanInstanceState.java:294) at org.apache.geronimo.gbean.runtime.GBeanInstanceState.start(GBeanInstanceState.java:102) at org.apache.geronimo.gbean.runtime.GBeanInstanceState.startRecursive(GBeanInstanceState.java:124) at org.apache.geronimo.gbean.runtime.GBeanInstance.startRecursive(GBeanInstance.java:553) at org.apache.geronimo.kernel.basic.BasicKernel.startRecursiveGBean(BasicKernel.java:379) at org.apache.geronimo.kernel.config.ConfigurationUtil.startConfigurationGBeans(ConfigurationUtil.java:448) at org.apache.geronimo.kernel.config.KernelConfigurationManager.start(KernelConfigurationManager.java:187) at org.apache.geronimo.kernel.config.SimpleConfigurationManager.startConfiguration(SimpleConfigurationManager.java:530) at org.apache.geronimo.kernel.config.SimpleConfigurationManager.startConfiguration(SimpleConfigurationManager.java:511) at org.apache.geronimo.kernel.config.SimpleConfigurationManager$$FastClassByCGLIB$$ce77a924.invoke(<generated>) at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53) at org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38) at org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:124) at org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:865) at org.apache.geronimo.kernel.basic.BasicKernel.invoke(BasicKernel.java:239) at org.apache.geronimo.kernel.KernelGBean.invoke(KernelGBean.java:342) at org.apache.geronimo.kernel.KernelGBean$$FastClassByCGLIB$$1cccefc9.invoke(<generated>) at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53) at org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38) at org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:124) at org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:865) at org.apache.geronimo.kernel.basic.BasicKernel.invoke(BasicKernel.java:239) at org.apache.geronimo.system.jmx.MBeanGBeanBridge.invoke(MBeanGBeanBridge.java:168) at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(DynamicMetaDataImpl.java:213) at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:220) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:815) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:784) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1410) at javax.management.remote.rmi.RMIConnectionImpl.access$100(RMIConnectionImpl.java:81) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1247) at java.security.AccessController.doPrivileged(Native Method) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1350) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:784) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294) at sun.rmi.transport.Transport$1.run(Transport.java:153) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:149) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707) at java.lang.Thread.run(Thread.java:595) |
Without delving into much detail it boils down to patching org.hibernate.ejb.Ejb3Configuration
to avoid NPE. Download the class from its source code repository at http://fisheye.jboss.com/browse/Hibernate/entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java and patch it with the following changes:
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
--- src/org/hibernate/ejb/Ejb3Configuration.java 2007-11-30 13:36:31.234375000 +0100 +++ src/org/hibernate/ejb/Ejb3Configuration.java.patched 2007-11-30 13:39:33.609375000 +0100 @@ -341,9 +341,11 @@ boolean[] detectArtifactForOtherJars = getDetectedArtifacts( info.getProperties(), null, false ); boolean[] detectArtifactForMainJar = getDetectedArtifacts( info.getProperties(), null, info.excludeUnlistedClasses() ); + if (info.getJarFileUrls() != null) { for ( URL jar : info.getJarFileUrls() ) { scanForClasses( jar, packages, entities, hbmFiles, detectArtifactForOtherJars, searchForORMFiles ); } + } scanForClasses( info.getPersistenceUnitRootUrl(), packages, entities, hbmFiles, detectArtifactForMainJar, searchForORMFiles ); Properties properties = info.getProperties() != null ? |
...
The plan configures necessary Geronimo resources to deploy JBoss Seam's booking sample application.
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
<?xml version="1.0" encoding="UTF-8"?> <application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <moduleId> <groupId>org.jboss.seam.examples.jee5</groupId> <artifactId>jboss-seam-jee5</artifactId> <version>2.0.0.GA</version> <type>ear</type> </moduleId> <dependencies> <dependency> <groupId>org.apache.geronimo.hibernate.transaction</groupId> <artifactId>geronimo-hibernate-transaction-manager-lookup</artifactId> <type>jar</type> </dependency> </dependencies> </environment> <module> <web>jboss-seam-jee5.war</web> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <moduleId> <groupId>org.jboss.seam.examples.jee5</groupId> <artifactId>jboss-seam-jee5</artifactId> <version>2.0.0.GA</version> <type>war</type> </moduleId> </environment> <context-root>/seam-jee5</context-root> </web-app> </module> <module> <ejb>jboss-seam-jee5.jar</ejb> <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <moduleId> <groupId>org.jboss.seam.examples.jee5</groupId> <artifactId>jboss-seam-jee5</artifactId> <version>2.0.0.GA</version> <type>jar</type> </moduleId> </environment> <!-- overrides what's in the module's persistence.xml --> <persistence xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="bookingDatabase"> <jta-data-source>jdbc/__default</jta-data-source> <class>org.jboss.seam.example.booking.Booking</class> <class>org.jboss.seam.example.booking.Hotel</class> <class>org.jboss.seam.example.booking.User</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="hibernate.transaction.manager_lookup_class" value="org.apache.geronimo.hibernate.transaction.GeronimoTransactionManagerLookup" /> </properties> </persistence-unit> <!-- change the way the default PU works - make it an alias to bookingDatabase PU --> <persistence-unit name="cmp"> <class>org.jboss.seam.example.booking.Booking</class> <class>org.jboss.seam.example.booking.Hotel</class> <class>org.jboss.seam.example.booking.User</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> </persistence-unit> </persistence> </openejb-jar> </module> <ext-module> <connector>seam-jee5-dbpool</connector> <external-path xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2"> <dep:groupId>org.tranql</dep:groupId> <dep:artifactId>tranql-connector-derby-embed-xa</dep:artifactId> <dep:type>rar</dep:type> </external-path> <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <moduleId> <groupId>org.jboss.seam.examples.jee5</groupId> <artifactId>booking-dbpool</artifactId> <version>2.0.0.GA</version> <type>rar</type> </moduleId> <dependencies> <dependency> <groupId>org.apache.geronimo.configs</groupId> <artifactId>system-database</artifactId> <type>car</type> </dependency> </dependencies> </environment> <resourceadapter> <outbound-resourceadapter> <connection-definition> <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface> <connectiondefinition-instance> <name>jdbc/__default</name> <config-property-setting name="DatabaseName">SystemDatabase</config-property-setting> <connectionmanager> <local-transaction /> <single-pool> <max-size>100</max-size> <blocking-timeout-milliseconds>5000</blocking-timeout-milliseconds> <select-one-assume-match /> </single-pool> </connectionmanager> </connectiondefinition-instance> </connection-definition> </outbound-resourceadapter> </resourceadapter> </connector> </ext-module> </application> |
...