Archive

Archive for the ‘JBoss’ Category

Error loading element Identity with component name null and component class null

10 December 2010 2 comments

This error is related to this post, and is solved by the exact same manner.

1) Edit your application.xml and move the jboss-seam.jar module to the top.
2) Edit each MANIFEST.MF file of the rest of your modules defined in the application.xml and remove the jboss-seam.jar entry.
3) Rebuild and redeploy your ear.

Advertisements
Categories: Java, JBoss, Seam, WebLogic

java.lang.ClassCastException: YOUR_REPORT_NAME_1290416522329_455758 cannot be cast to net.sf.jasperreports.engine.fill.JREvaluator

3 December 2010 9 comments

Another classloading issue. While jasper reports work fine on JBoss, on WebLogic they fail with the exception

net.sf.jasperreports.engine.JRException: Error loading expression class : MYREPORT_1290416522329_455758
...
Caused by: java.lang.ClassCastException: MYREPORT_1290416522329_455758 cannot be cast to net.sf.jasperreports.engine.fill.JREvaluator
at net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(JRAbstractJavaCompiler.java:101)

This is easily resolved. In my configuration it was just a matter of moving my jasper jar file from the root of ear to the WEB-INF/lib folder of my web app, in order to be picked up by a different classloader. If this does not work try moving the jasper jar file around in different locations, one of them will work.

Categories: Jasper, Java, JBoss, WebLogic Tags: , , ,

No phase id bound to current thread (make sure you do not have two SeamPhaseListener instances installed)

1 December 2010 Leave a comment

Caused by java.lang.IllegalStateException with message: "No phase id bound to current thread (make sure you do not have two SeamPhaseListener instances installed)

Another JBoss to WebLogic migration issue. This error is caused by having the jboss-seam.jar file twice in the classpath or by loading it more than once. This link explains the problem for JBoss in more details, but the same solution can be applied to WebLogic. Move the loading of the jboss-seam.jar first in the application.xml and remove any reference of it in all the MANIFEST.MF files in the rest of the modules declared in application.xml.

application.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
  <display-name>store-ear</display-name>
  <module>
    <ejb>jboss-seam.jar</ejb>
  </module>
  <module>
    <web>
      <web-uri>store.war</web-uri>
      <context-root>/store</context-root>
    </web>
  </module>
  <module>
    <ejb>storeModel-ejb.jar</ejb>
  </module>
  <module>
    <ejb>storeCommon-ejb.jar</ejb>
  </module>
  <module>
    <ejb>store-ejb.jar</ejb>
  </module>
  <module>
    <ejb>store-products.jar</ejb>
  </module>
</application>

MANIFEST.MF in store-ejb.jar, before jboss-seam.jar removal

Manifest-Version: 1.0
Class-Path: storeCommon-ejb.jar
 antlr-runtime.jar 
 jboss-seam.jar
 drools-compiler.jar 
 drools-core.jar 
 jboss-el.jar 
 jbpm-jpdl.jar 
 mvel14.jar 
 richfaces-api.jar 

MANIFEST.MF in store-ejb.jar, after jboss-seam.jar removal

Manifest-Version: 1.0
Class-Path: storeCommon-ejb.jar
 antlr-runtime.jar 
 drools-compiler.jar 
 drools-core.jar 
 jboss-el.jar 
 jbpm-jpdl.jar 
 mvel14.jar 
 richfaces-api.jar 
Categories: Java, JBoss, Seam, WebLogic Tags: , , ,

Error loading element EntityTransaction with component name null and component class null

30 November 2010 8 comments

The exception java.lang.RuntimeException: Error loading element EntityTransaction with component name null and component class null is caused by this line

<transaction:entity-transaction entity-manager="#{entityManager}"/>

in the components.xml file. In order to fix the error you have to replace the

   <persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/myManagerFactory"/>

with

   <persistence:entity-manager-factory name="entityManagerFactory" persistence-unit-name="myPersistenceUnit"/>
   <persistence:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{entityManagerFactory}" />

and remove the

<transaction:entity-transaction entity-manager="#{entityManager}"/>

line.

The myPersistenceUnit is the name of the persistence unit in persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
             version="1.0">
             
   <persistence-unit name="myPersistenceUnit" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>

      <jta-data-source>myDatasource</jta-data-source>

      <properties>
         <property name="hibernate.connection.provider_class" value="org.hibernate.connection.DatasourceConnectionProvider"/>
	   <property name="hibernate.connection.datasource" value="myDatasource"/>
	   <property name="transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
	   <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
	   <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WeblogicTransactionManagerLookup"/>
         <property name="hibernate.dialect" value="gr.my.company.util.MyAS400Dialect"/>
         <property name="hibernate.hbm2ddl.auto" value="validate"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="hibernate.default_schema" value="MYSCHEMA"/>
      </properties>
   </persistence-unit>  
    
</persistence>

No EJBs found in the ejb-jar file ‘MyApplication.jar’. Please ensure the ejb-jar contains EJB declarations via an ejb-jar.xml deployment descriptor or at least one class annotated with the @Stateless, @Stateful or @MessageDriven EJB annotation

30 November 2010 4 comments

Another migration error. In my application.xml I have defined an <ejb> module but my ejb project only contains EJB 3.0 @Entity annotated beans. WebLogic (10.3) doesn’t like this and expects a @Stateless, @Stateful or @MessageDriven annotated bean. It doesn’t find any and throws a

No EJBs found in the ejb-jar file ‘MyApplication.jar’. Please ensure the ejb-jar contains EJB declarations via an ejb-jar.xml deployment descriptor or at least one class annotated with the @Stateless, @Stateful or @MessageDriven EJB annotation

exception. The exact same jar file works fine on JBoss and WebSphere though. Not sure which one is right but I had to add a dummy @Stateless EJB in the jar file order to make it work.

Categories: JBoss, Seam, WAS, WebLogic Tags: , , , ,

java.lang.UnsupportedOperationException: The user must supply a JDBC connection

26 November 2010 5 comments

If you get this with Hibernate it probably means that you have an error, or an incomplete persistence.xml file. I got this while migrating from JBoss to WebLogic server and had forgotten to migrate the configuration from JBoss’ *-ds.xml to persistence.xml.

It happens because of this bit of code (Hibernate’s ConnectionProviderFactory.java)

ConnectionProvider connections;
String providerClass = properties.getProperty(Environment.CONNECTION_PROVIDER);
if ( providerClass!=null ) {
	try {
		log.info("Initializing connection provider: " + providerClass);
		connections = (ConnectionProvider) ReflectHelper.classForName(providerClass).newInstance();
	}
	catch ( Exception e ) {
		log.error( "Could not instantiate connection provider", e );
		throw new HibernateException("Could not instantiate connection provider: " + providerClass);
	}
}
else if ( properties.getProperty(Environment.DATASOURCE)!=null ) {
	connections = new DatasourceConnectionProvider();
}
else if ( properties.getProperty(Environment.URL)!=null ) {
	connections = new DriverManagerConnectionProvider();
}
else {
	connections = new UserSuppliedConnectionProvider();
}

It tries to load several connection providers based on the Environment properties, it can’t find any connection providers (since their corresponding properties are not defined in the persistence.xml) and it just returns the default UserSuppliedConnectionProvider which, alas, it’s getConnection method is the following

public Connection getConnection() {
	throw new UnsupportedOperationException("The user must supply a JDBC connection");
}

After fixing the error, my persistence.xml is the following

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
             version="1.0">
             
   <persistence-unit name="myUnit" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>

      <jta-data-source>myDatasource</jta-data-source>

      <properties>
		<property name="hibernate.connection.provider_class" value="org.hibernate.connection.DatasourceConnectionProvider"/>
	   	<property name="hibernate.connection.datasource" value="myDatasource"/>
	   	<property name="transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
	   	<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
	   	<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WeblogicTransactionManagerLookup"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
        <property name="hibernate.hbm2ddl.auto" value="validate"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hibernate.default_schema" value="MYSCHEMA"/>
	 <property name="hibernate.query.factory_class" value="org.hibernate.hql.ast.ASTQueryTranslatorFactory"/>
      </properties>
   </persistence-unit>  
    
</persistence>