Skip to main content

Wrong XAState: 0

25 replies [Last post]
glassfox
Offline
Joined: 2009-01-28

Hi,

i get continuously the error: "java.lang.illegalStateException: Wrong XAState: 0"
Here the full history:

[#|2009-02-17T08:13:27.625+0100|SEVERE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=25;_ThreadName=p: thread-pool-1; w: 16;_RequestID=b2c29646-8a11-420a-b5b5-cc9be2327e28;|RAR5029:Unexpected exception while registering component.
java.lang.IllegalStateException: Wrong XAState: 0
at com.sun.jts.jta.TransactionState.startAssociation(TransactionState.java:323)
at com.sun.jts.jta.TransactionImpl.enlistResource(TransactionImpl.java:205)
at com.sun.enterprise.distributedtx.J2EETransaction.enlistResource(J2EETransaction.java:562)
at com.sun.enterprise.distributedtx.J2EETransactionManagerImpl.enlistResource(J2EETransactionManagerImpl.java:372)
at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.enlistResource(J2EETransactionManagerOpt.java:169)
at com.sun.enterprise.resource.ResourceManagerImpl.registerResource(ResourceManagerImpl.java:144)
at com.sun.enterprise.resource.ResourceManagerImpl.enlistResource(ResourceManagerImpl.java:102)
at com.sun.enterprise.resource.PoolManagerImpl.getResource(PoolManagerImpl.java:216)
at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:327)
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:189)
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:158)
at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:108)
at com.gf.costo.engine.db.DbManager.getConnection(DbManager.java:83)
at com.gf.costo.engine.db.DbManager.GetDepotId(DbManager.java:3685)
at com.gf.costo.engine.db.DbManager.GetAssetsOfDepot(DbManager.java:1241)
at com.gf.costo.engine.db.DbManager.GetActiveAssets(DbManager.java:1201)
at com.gf.costo.engine.calcengine.CalcEngine.RecalculateSingleIntradayDepot(CalcEngine.java:435)
at com.gf.costo.engine.calcengine.CalcEngine.CalculateAllDepots(CalcEngine.java:235)
at com.gf.costo.engine.scheduler.Scheduler.handleIntradayStockEvent(Scheduler.java:137)
at com.gf.costo.engine.scheduler.Scheduler.runSchedulerTask(Scheduler.java:110)
at com.gf.costo.engine.BackendManagerBean.handleTimeout(BackendManagerBean.java:92)
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:597)
at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:2824)
at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1401)
at com.sun.ejb.containers.EJBTimerService.access$100(EJBTimerService.java:99)
at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:1952)
at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.service(EJBTimerService.java:1948)
at com.sun.ejb.containers.util.WorkAdapter.doWork(WorkAdapter.java:75)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)

There is a timer which initiates read and write actions to the database (postgres SQL with JDBC4 driver) and after some initiations I get this error and timer is got killed. My database pool has 200 connections, this should be definitely enougth for this task... I am using Glassfish V2, JDK 6 and postgres 8.2. Any ideas what's going wrong here?

Thanks,
Glassfox

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
glassfox
Offline
Joined: 2009-01-28

No ideas any more?

Marina Vatkina

Can you try Derby instead?

Another thing to try- change connection-validation-method="auto-commit" to be
"table"?

thanks,
-marina

glassfish@javadesktop.org wrote:
> No ideas any more?
> [Message sent by forum member 'glassfox' (glassfox)]
>
> http://forums.java.net/jive/thread.jspa?messageID=333815
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

jr158900
Offline
Joined: 2005-04-13

any reason why the DBManager does "conn.setAutoCommit(true)"
Can you comment it and try ?

Thanks,
-Jagadish

glassfox
Offline
Joined: 2009-01-28

I don't know it exactly now... I tried it out to comment out this line but it has no effect...

any reason why the DBManager does "conn.setAutoCommit(true)"
Can you comment it and try ?

Thanks,
-Jagadish

glassfox
Offline
Joined: 2009-01-28

I tried out a lot of stuff and know now what the problem is. But I don't know how to solve it. The problem is the timer. If I execute the code through for example an user action, there are no errors. If I execute the same code initiated by an expired timer I get this curious "Wrong XAState: 0" error.

Postgres Poolsize and Thread.sleep() during database accesses have no effect.

Could this be an EJB Timer bug?

mvatkina
Offline
Joined: 2005-04-04

Did you try to use Derby?

Can you change javax.sql.ConnectionPoolDataSource to javax.sql.DataSource? Or use XA datasource altogether?

When you use a timer, it comes with the XA datasource access because the timer instances are stored in the database. When you call your method directly, it uses a single (non-XA) connection. And that is a big difference :).

thanks,
-marina

glassfox
Offline
Joined: 2009-01-28

Thank you for your help.

>Did you try to use Derby?
No, I din't. Why do you think Derby is better than postgres? When I migrate to Derby, is there a possibility to (automatically) migrate also the data in the database?

>Can you change javax.sql.ConnectionPoolDataSource to javax.sql.DataSource? Or use XA datasource altogether?
I changed the setting to javax.sql.DataSource, but it had not effect. What do you mean with "use XA datasource altogether"? Where can I configure it?

But I found something what helped: I increased the "Initial and Minimum Pool Size" from 32 (default) to 64. The error vanished, but I don't know if it just depends on how many times per timer event a connection is requested. May be the error will occure again with more connection requests. Do you now what the maximal possible value is for the Initial and Minimum Pool Size? The value of 128 seemed not to be accepted.

allenjsomb
Offline
Joined: 2009-03-19

There are two type of transactions we can talk about in general (pertaining to this thread).

1) There is the transaction that you can write using SQL which you (the programmer) write yourself.
2) There is the transaction that java handles at a system level which can apply to any operation or series of operations you require to be performed from beginning to end without error (including database operations).

By setting non-transactional-connections to true you will not get the protection from system failure as described in number 2.

I welcome others to chime in on this because I am hardly an authority.

glassfox
Offline
Joined: 2009-01-28

Thanks four your advise allenjsomb. After several days of testing I can say that was the solution!

allenjsomb
Offline
Joined: 2009-03-19

I've got one more idea:

Do you need transactional capability. If not, you can set your pool to return non-transactional-connections.

Set non-transactional-connections="true" in your configuration.

glassfox
Offline
Joined: 2009-01-28

Thank you for your help allenjsomb. I'll think about it. But in fairness I must say I don't know if need the transactional capability or not. What are the criteria for this decision?

allenjsomb
Offline
Joined: 2009-03-19

sorry - i should read more carefully - i see you have already tried changing the resource type to java.sql.ConnectionPoolDataSource.

allenjsomb
Offline
Joined: 2009-03-19

glassfox:

I was having the same issue specific within an EJB timer. I was using mysql and not postgres. I was able to resolve my problem by changing the resource type to java.sql.ConnectionPoolDataSource.

Have you tried this?

mvatkina
Offline
Joined: 2005-04-04

What does your timeout method do in terms of transactions and connections?

thanks,
-marina

glassfox
Offline
Joined: 2009-01-28

It starts a method which reads the configuration out of the database first, to know what to do (depending on the weekday and time). Than, if there is something to do it aquires data from internet and writes it to the database. The first timer is 5 minutes, the second 1 hour.

mvatkina
Offline
Joined: 2005-04-04

Does it call other EJBs for that? What is the transaction setting on the timeout bean and its method?

What do you mean by the first timer and the 2nd timer?

thanks,
-marina

glassfox
Offline
Joined: 2009-01-28

No, there is just one EJB.

This is the Timeout Method of my bean:

@Timeout
@Override
public void handleTimeout(Timer timer) {
scheduler.runSchedulerTask(timer);
}

And than:

public void runSchedulerTask(Timer timer) {
String timerEvent = (String)timer.getInfo();
if(timerEvent.compareTo("aaa") == 0) {handleaaaEvent();}
else if(timerEvent.compareTo("bbb") == 0) {handlebbbEvent();}
}

As you can see, there are two active timers (here named "aaa" and "bbb"). For each timer there is the corrersponding handler method. In these methods than I read from the database and write to it.

mvatkina
Offline
Joined: 2005-04-04

Something goes wrong with the transaction association down the call stack. Are CalcEngine and DBManager EJBs or POJOs?

thanks,
-marina

glassfox
Offline
Joined: 2009-01-28

They are POJOs. I have only one EJB in the whole application.

Marina Vatkina

How do you get a hold of a DataSource?

thanks,
-marina

glassfish@javadesktop.org wrote:
> They are POJOs. I have only one EJB in the whole application.
> [Message sent by forum member 'glassfox' (glassfox)]
>
> http://forums.java.net/jive/thread.jspa?messageID=332999
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

glassfox
Offline
Joined: 2009-01-28

I don't know what you exactly mean. Here my code for jdbc lookup and creation of a database connection:
[code]
// --------------------------------------------------------------------------------------------------------------------------------------------------
public class DbManager {

@Resource(name = "jdbc/Postgres")
private DataSource db = null;
private LogManager log = null;
private Utils utils = null;
private static DbManager instance = null;
private String defaultDate = "2222-12-12 12:12:12.1"; //have to use this instead of NULL due to data base restrictions

/** Creates a new instance of DbManager */
protected DbManager() {
log = new LogManager();
log.traceMethodeDetails();

utils = new Utils();

Context c;
try {
c = new InitialContext();
db = (DataSource) c.lookup("jdbc/Postgres");
log.debug("COSTO: lookup of datasource jdbc/Postgres successful");
} catch (NamingException ex) {
log.debug("Could not lookup JNDI name...("+ex.getMessage()+")");
}
}

public static DbManager getInstance() {
if(instance == null) {
instance = new DbManager();
}
return instance;
}

// ---- reserves a connection from db connection pool and returns it
private Connection getConnection()
{
Connection con = null;
try {
con = db.getConnection();
con.setAutoCommit(true);
} catch (SQLException ex) {
log.internalError("Could not get database connection... ("+ex.getMessage()+")");
}

return con;
}

// ---- releases a previous requested connection from the connection pool
void releaseConnection(Connection con) {
try{
if ((con != null) && (con.isClosed() == false)){
con.close();
con = null;
}
} catch (SQLException ex) {
log.internalError("Could not close database connection... ("+ex.getMessage()+")");
}
}
[/code]

Thanks

Martin Gainty

where is the driver name specified?

Martin
______________________________________________
Disclaimer and confidentiality note
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission.

> Date: Fri, 20 Feb 2009 17:55:19 -0800
> From: glassfish@javadesktop.org
> To: users@glassfish.dev.java.net
> Subject: Re: Wrong XAState: 0
>
> I don't know what you exactly mean. Here my code for jdbc lookup and creation of a database connection:
> [code]
> // --------------------------------------------------------------------------------------------------------------------------------------------------
> public class DbManager {
>
> @Resource(name = "jdbc/Postgres")
> private DataSource db = null;
> private LogManager log = null;
> private Utils utils = null;
> private static DbManager instance = null;
> private String defaultDate = "2222-12-12 12:12:12.1"; //have to use this instead of NULL due to data base restrictions
>
> /** Creates a new instance of DbManager */
> protected DbManager() {
> log = new LogManager();
> log.traceMethodeDetails();
>
> utils = new Utils();
>
> Context c;
> try {
> c = new InitialContext();
> db = (DataSource) c.lookup("jdbc/Postgres");
> log.debug("COSTO: lookup of datasource jdbc/Postgres successful");
> } catch (NamingException ex) {
> log.debug("Could not lookup JNDI name...("+ex.getMessage()+")");
> }
> }
>
> public static DbManager getInstance() {
> if(instance == null) {
> instance = new DbManager();
> }
> return instance;
> }
>
> // ---- reserves a connection from db connection pool and returns it
> private Connection getConnection()
> {
> Connection con = null;
> try {
> con = db.getConnection();
> con.setAutoCommit(true);
> } catch (SQLException ex) {
> log.internalError("Could not get database connection... ("+ex.getMessage()+")");
> }
>
> return con;
> }
>
> // ---- releases a previous requested connection from the connection pool
> void releaseConnection(Connection con) {
> try{
> if ((con != null) && (con.isClosed() == false)){
> con.close();
> con = null;
> }
> } catch (SQLException ex) {
> log.internalError("Could not close database connection... ("+ex.getMessage()+")");
> }
> }
> [/code]
>
> Thanks
> [Message sent by forum member 'glassfox' (glassfox)]
>
> http://forums.java.net/jive/thread.jspa?messageID=333207
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

_________________________________________________________________
It’s the same Hotmail®. If by “same” you mean up to 70% faster.
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_AE_Same_022009
[att1.html]

glassfox
Offline
Joined: 2009-01-28

I have just copied the postgresql-8.3-604.jdbc4.jar to the lib folder of the domain and have only the allready posted JDBC stuff in my code... In the application server I created the JDBC ressource jdbc/Postgres with the Pool PostgresPool. Should I specifiy more JDBC stuff anywhere?

Marina Vatkina

Can you post the PostgresPool settings from domain.xml?

thanks,
-marina

glassfish@javadesktop.org wrote:
> I have just copied the postgresql-8.3-604.jdbc4.jar to the lib folder of the
> domain and have only the allready posted JDBC stuff in my code... In the
> application server I created the JDBC ressource jdbc/Postgres with the Pool
> PostgresPool. Should I specifiy more JDBC stuff anywhere? [Message sent by
> forum member 'glassfox' (glassfox)]
>
> http://forums.java.net/jive/thread.jspa?messageID=333264
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional
> commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

glassfox
Offline
Joined: 2009-01-28

Here is the whole content of my domain.xml:
[code]

−

−

−





−


−



−

"JBI Framework LifecycleModule"


−





−

c2web resource

−


−


−


−



−

−

−


−


−




−


−







−



−



−




−

−




−

−

−







−




−



−



−

−

−


−

−




−


−


−

−


−


−


−



−




−

-Djava.awt.headless=true
-XX:MaxPermSize=192m
-client
−

-Djava.endorsed.dirs=${com.sun.aas.installRoot}/lib/endorsed

−

-Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy

−

-Djava.security.auth.login.config=${com.sun.aas.instanceRoot}/config/login.conf

-Dsun.rmi.dgc.server.gcInterval=3600000
-Dsun.rmi.dgc.client.gcInterval=3600000
-Xmx512m
−

-Djavax.net.ssl.keyStore=${com.sun.aas.instanceRoot}/config/keystore.jks

−

-Djavax.net.ssl.trustStore=${com.sun.aas.instanceRoot}/config/cacerts.jks

−

-Djava.ext.dirs=${com.sun.aas.javaRoot}/lib/ext${path.separator}${com.sun.aas.javaRoot}/jre/lib/ext${path.separator}${com.sun.aas.instanceRoot}/lib/ext${path.separator}${com.sun.aas.derbyRoot}/lib

-Djdbc.drivers=org.apache.derby.jdbc.ClientDriver
−

-Djavax.management.builder.initial=com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder

−

-Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory

−

-Dcom.sun.enterprise.taglibs=appserv-jstl.jar,jsf-impl.jar

-Dcom.sun.enterprise.taglisteners=jsf-impl.jar
-XX:NewRatio=2
−


−




−

−

















[/code]