views:

444

answers:

2

I'm running Spring and Hibernate's implementation of JPA on Sun's GlassFish Enterprise Server with MySQL.

When I try to delete stuff from the database:

Query q = entityManager.createQuery("DELETE FROM SomeEntity e");
q.executeUpdate();

I get the error:

Caused by: java.sql.SQLException: Error in allocating a connection. Cause: java.lang.RuntimeException: Got exception during XAResource.start:
at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:115)
at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:69)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:550)

However, all other queries that invoke getResultList() works:

Query q = entityManager.createQuery("SELECT e FROM SomeEntity e");
q.getResultList();

For some reason the JDBC driver can't get a connect for executeUpdate() yet it works for getResultList(). The application's MySQL account has all privileges including INSERT and DELETE.

A: 

I am supposing you are using jta-datasource. And I think, you have no transaction started. Or probably you have some problems with you datasources. So, you should test your datasources (you could define both jta-data-source and non-jta-data-source). And you need enshure that all updates are done in a transactional context.

serge_bg
A: 

In general XAResource means that you are inside distributed transaction. You must use XA driver in this case for DB data source and connection (e.g. com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)

sibnick