Archive for the 'JBoss' Category

 

JBoss vs WebLogic – JNDI issues..

Jun 11, 2010 in JBoss, Weblogic

In JBoss, one can get a reference to the Remote bean directly:

try
{
    context = new InitialContext(jndiprops);
    BookTestBeanRemote beanRemote = 
        (BookTestBeanRemote) context.lookup("BookTestBean/remote");
    beanRemote.test(); 
} catch (NamingException e) {
    ...
}

In WebLogic 10.3, I was not able to do the same thing.
The exception said that WebLogic JNDI failed to find the bean.
As some searches indicated, I should have used something like this for
the lookup string: “BookTestBean#com.blah.BookTestBeanRemote” ..
I tried all kinds of combinations but I was not able to make it work.

In JBoss, the “Home” interface is not required. In WebLogic, it is required.
This may have something to do with different levels of implementation
of the EJB spec but I would think JBoss 5 and WebLogic 10
should be pretty close in compatibility.. maybe.. what do I know?

Based on this, the only way I was able to make WebLogic work, was via
the “Home” interface:

Context context;
try
{
    context = new InitialContext(jndiprops);

    UserTransaction txn = (UserTransaction) context.lookup("javax.transaction.UserTransaction");
    if (txn != null) {
        String jndiLookupStr = "";
	// jndiLookupStr = "BookTestBean#de.laliluna.library.BookTestBeanRemote";
        jndiLookupStr = "BookTestBean";

        Object oref = context.lookup(jndiLookupStr);
        BookTestBeanHome homeRef = (BookTestBeanHome) PortableRemoteObject.narrow(oref,
           BookTestBeanHome.class);
        BookTestBeanRemote beanRef = homeRef.create();

        txn.begin();
        beanRef.test(); 
        txn.commit();
    } // txn != null
}
catch (Exception e) {
    e.printStackTrace();
}

This page says that remote reference retrieval is possible with WebLogic:

http://camelcase.blogspot.com/2009/04/how-to-call-remote-transactional.html

JBoss vs WebLogic notes – persistence..

Jun 11, 2010 in JBoss, Weblogic

In JBoss, this works:

List someBooks = em.createQuery("FROM Book b WHERE b.author=:name")
    .setParameter("name", "Sebastian").getResultList();

In WebLogic, I had to specify SELECTs:

List someBooks = em.createQuery("SELECT b FROM Book b WHERE b.author=:name")
    .setParameter("name", "Sebastian").getResultList();

If I have time, I will dig further and see why they behave differently but I suspect
that JBoss CMP is used automatically while in WebLogic, OpenJPA is used which
requires the “SELECT” syntax.

Good example on client transaction setup:

http://camelcase.blogspot.com/2009/04/how-to-call-remote-transactional.html

JBoss vs WebLogic tidbits..

Jun 10, 2010 in JBoss, Weblogic

Porting JBoss EJB3s to WebLogic is not trivial.. Here are some of the compliance exceptions:

  • weblogic.ejb.container.compliance.ComplianceException: Home methods are not allowed on session beans: BookTestBean.test()

  • weblogic.ejb.container.compliance.ComplianceException: In EJB BookTestBean, method test() on the home interface does not throw java.rmi.RemoteException. This is a required exception.

  • weblogic.ejb.container.compliance.ComplianceException: In EJB BookTestBean, the home interface de.laliluna.library.BookTestBeanLocal must extend the javax.ejb.EJBHome interface.

  • weblogic.ejb.container.compliance.ComplianceException: In EJB BookTestBean, the home interface of a stateless session bean must have one create method that takes no arguments.

  • weblogic.ejb.container.compliance.ComplianceException: In EJB BookTestBean, the return type for the home create method create() must be the remote interface type of the bean.

Persistence-related exception:

org.apache.openjpa.util.MetaDataException: “de.laliluna.library.Book.id” declares generator name “book_sequence”, but uses the AUTO generation type. The only valid generator names under AUTO are “uuid-hex” and “uuid-string”.

To fix it, change this:

// For JBoss
@GeneratedValue(strategy = GenerationType.AUTO, generator = "book_sequence")

to this:

// For WebLogic
@GeneratedValue(strategy = GenerationType.AUTO)

More on persistence.. the default provider for WebLogic is a package named ‘Kodo’.
To set the OpenJPA (Java Persistence API) provider, add the element
to persistence.xml , like this:

<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="FirstEjb3Tutorial" transaction-type="JTA">
                <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
                <properties>
                        <property name="openjpa.ConnectionURL" value="jdbc:pointbase:server://localhost:18888/fe3t"/>
                        <property name="openjpa.ConnectionDriverName" value="com.pointbase.jdbc.jdbcUniversalDriver"/>
                        <property name="openjpa.ConnectionUserName" value="fe3t"/>                   
                        <property name="openjpa.ConnectionPassword" value="fe3t"/>
                        <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
                </properties>
        </persistence-unit>
</persistence>

Note the “openjpa.” qualifier .. Persistence will not work without it ..

EJB container interface..

Jun 07, 2010 in EJB, JBoss, Weblogic

  1. ejbCreate, ejbPostCreate
  2. ejbLoad, ejbStore
  3. ejbActivate, ejbPassivate