Bitter bites with Java

Hi,

Some of you might have come across the following strange exception when moving to Jboss5 from Jboss4.x.

Adding multiple last resources is disallowed. Current resource is [EMAIL
PROTECTED]
| 16:17:18,000 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
| 16:17:18,000 ERROR [JDBCExceptionReporter] Could not enlist in transaction
on entering meta-aware object!; – nested throwable:
(javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist
resource, see the previous warnings. tx=TransactionImple < ac, BasicAction:
-53e0d9e7:77e:469b7d96:41 status: ActionStatus.ABORT_ONLY >); – nested
throwable: (org.jboss.resource.JBossResourceException: Could not enlist in
transaction on entering meta-aware object!; – nested throwable:
(javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist
resource, see the previous warnings. tx=TransactionImple < ac, BasicAction:
-53e0d9e7:77e:469b7d96:41 status: ActionStatus.ABORT_ONLY >))
| 16:17:18,000 FATAL [application] javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: Cannot open connection
| javax.faces.el.EvaluationException: javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: Cannot open connection

This happens when :

1. You have 2 EAR files in a single server instance. Not just 2 ear files, but from within a transaction of a deployed EAR file, when you try to access the other EAR file, get some data from there and try to commit the transaction. This is not allowed in arjuna API (AFAIK). To fix this, edit JBOSS_HOME/server/default/conf/jbossjta-properties.xml and add the following line

<property name=”com.arjuna.ats.jta.allowMultipleLastResources” value=”true” />

The problem does not stop here..The datasource has to support it.

Modify the *ds.xml to look like this ( localtxdatasource would not work) :

<?xml version=”1.0″ encoding=”UTF-8″?>
<datasources>
<xa-datasource>
<jndi-name>CatMgrDS</jndi-name>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
<xa-datasource-property name=”URL”>jdbc:mysql://192.168.157.57:3306/30cm</xa-datasource-property>
<xa-datasource-property name=”User”>root</xa-datasource-property>
<xa-datasource-property name=”Password”>root</xa-datasource-property>
<!– the minimum size of the connection pool –>
<min-pool-size>1</min-pool-size>
<!– The maximum connections in a pool/sub-pool –>
<max-pool-size>4</max-pool-size>
</xa-datasource>
</datasources>

Next step is to make sure you have the latest version of mysql-connector(in my case atleast). Versions prior to 5.1.10 doesn’t support XA datasource(ref :http://marc.info/?l=kandula-dev&m=113945114400475&w=2) I replaced my old mysql connector with the latest one.

Things should work fine then. will keep this writing up to date to my best possible extent :)




JBoss4.0.5 to JBoss 5GA

Posted by: Venugopal S on: February 2, 2009

Hi,

Our application runs on Jboss4.0.5 for almost 2.5 years now. One thing that was appealing me the most with Jboss5 was its proved performance wrt JBoss Messaging. We have been using JBossMQ for long.

The day wasn’t pleasant when i started exploring Jboss5. It threw all strange errors and Exceptions to a newbie like me at the outset. Ok.. After about 3/4th of a week was spent, i was gaining grip on the new beast Jboss5 (finally).

You should not be bewildered initially. I would like to mention few things i learnt the very hard way.

Migrating to Jboss5:

  • XML files are strictly validated against the schema. Hence we need to alter some of the XML files :

In application.xml we have to replace

<application xmlns=”http://java.sun.com/xml/ns/j2ee” version=”1.4″

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=”http://java.sun.com /xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd”>

<display-name>ss</display-name>

WITH

<?xml version=”1.0″ encoding=”UTF-8″?>
<application xmlns=”http://java.sun.com/xml/ns/javaee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/application_5.xsd”
version=”5″>


And the <description> tag should be removed.

In persistence.xml:

The root element was simple and plain. We need to update it to

<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″>

web.xml : Mixing <servlet> and <servlet-mapping> is not allowed in Jboss 5 and the dtd has to be updated to

<!DOCTYPE web-app

PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”

“http://java.sun.com/dtd/web-app_2_3.dtd”>

And in all the occurrences of

this.queueConnectionFactory = (QueueConnectionFactory) this.ctx

.lookup(“QueueConnectionFactory”);

we need to replace with

this.queueConnectionFactory = (QueueConnectionFactory) this.ctx

.lookup(“ConnectionFactory”);

jboss-app.xml which contains

<!DOCTYPE jboss-app

PUBLIC “-//JBoss//DTD J2EE Application 1.4//EN”

“http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd”>

has to be updated with the latest dtd as

<!DOCTYPE jboss-app

PUBLIC “-//JBoss//DTD Java EE Application 5.0//EN”

“http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd”>.

The annotations are a bit different in Jboss 5.

In a POJO class, we were using the JoinColumn annotations like

@ManyToOne

@JoinColumn(name = “orderid”, insertable = false)

which has to be modified to

@ManyToOne

@JoinColumns({@JoinColumn(name = “orderId”,referencedColumnName=”orderId”,insertable = false)})

referencedColumnName is a must in JBoss 5 for this annotation.

For JMS :

In case of Jboss4, all the JMS related stuff had to go in jbossmq-destinations-service.xml.

Sample element :

<mbean code=”org.jboss.mq.server.jmx.Queue”

name=”jboss.mq.destination:service=Queue,name=TotalOrderQueue”>

<attribute name=”JNDIName”>queue/TotalOrderQueue</attribute>

<attribute name=”RedeliveryDelay”>10000</attribute>

<attribute name=”RedeliveryLimit”>3</attribute>

<depends optional-attribute-name=”DestinationManager”>jboss.mq:service=DestinationManager</depends>

</mbean>

But in Jboss 5, Jboss messaging has replaced JbossMQ. Jboss messaging is significantly faster than JbossMQ(Ref : http://www.jboss.org/file-access/default/members/jbossmessaging/freezone/docs/userguide-2.0.0.alpha1/html/performance.html).

The configurations need to be tweaked a bit to be read as follows (also the configuration filename has changed to destinations-service.xml):

<mbean code=”org.jboss.jms.server.destination.QueueService”

name=”jboss.messaging.destination:service=Queue,name=TotalOrderQueue”

xmbean-dd=”xmdesc/Queue-xmbean.xml”>

<depends optional-attribute-name=”ServerPeer”>jboss.messaging:service=ServerPeer</depends>

<depends>jboss.messaging:service=PostOffice</depends>

</mbean>

Hope this helps!


  • whitelassiblog: jbossjta-properties.xml is present in JBOSS_HOME/checkout folder. Check it out !
  • Subinkrishna G: Hi Kuldeep, We (me & venu) were using Jboss 4 before migrating to 5.0 and then to 5.1. I don't have much idea about migrating from 3.x to 5.x.
  • Kuldeep: Hello, I'm migrating application from Jboss 3.2.6 to Jboss 5.1.0 GA. I've used EJB 2, Message Driven Beans, Hibernate. Could you please give

Categories

Archives