You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by James Adams <mo...@gmail.com> on 2008/12/02 22:13:35 UTC

Not creating database and executeQuery() errors with Hibernate+Spring+Atomikos

I am trying to use a Derby database (either embedded or network server) for
some DAO tests and I am getting the following errors:

Derby running Embedded: 

    (Spring configuration:)

    <bean id="dataSource"
          class="com.atomikos.jdbc.SimpleDataSourceBean"
          init-method="init"
          destroy-method="close">
        <property name="uniqueResourceName"><value>XADBMS</value></property>
        <!-- set the underlying driver class to use-->
        <property
name="xaDataSourceClassName"><value>org.apache.derby.jdbc.EmbeddedXADataSource40</value></property>
        <property name="xaDataSourceProperties">
           
<value>databaseName=lifecycle;createDatabase=create;shutdownDatabase=shutdown</value>
        </property>
        <property
name="exclusiveConnectionMode"><value>true</value></property>
        <property name="connectionPoolSize" value="10"/>
    </bean>

ERROR:

Error creating bean with name 'dataSource' defined in URL
[file:/C:/dev/projects/lifecycle/build/classes/applicationContext.xml]:
Invocation of init method failed; nested exception is java.sql.SQLException:
Database 'lifecycle' not found.
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'dataSource' defined in URL
[file:/C:/dev/projects/lifecycle/build/classes/applicationContext.xml]:
Invocation of init method failed; nested exception is java.sql.SQLException:
Database 'lifecycle' not found.
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1362)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
        at java.security.AccessController.doPrivileged(Native Method)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:413)
        at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:735)
        at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
        at
org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:199)
        at
org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:179)
        at
org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:158)
        at
org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105)
        at
org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:87)
        at
org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
Caused by: java.sql.SQLException: Database 'lifecycle' not found.
        at
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
Source)
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown
Source)
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown
Source)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown
Source)
        at
org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
        at
org.apache.derby.impl.jdbc.EmbedConnection.handleDBNotFound(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown
Source)
        at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown
Source)
        at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown
Source)
        at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
        at org.apache.derby.jdbc.EmbeddedDataSource.getConnection(Unknown
Source)
        at org.apache.derby.jdbc.EmbeddedDataSource.getConnection(Unknown
Source)
        at
org.apache.derby.jdbc.EmbeddedXADataSource.setupResourceAdapter(Unknown
Source)
        at
org.apache.derby.jdbc.EmbeddedXADataSource.getXAConnection(Unknown Source)
        at
com.atomikos.jdbc.XAConnectionFactory.getPooledConnection(XAConnectionFactory.java:309)
        at com.atomikos.jdbc.ConnectionPool.<init>(ConnectionPool.java:78)
        at
com.atomikos.jdbc.JtaDataSourceImp.<init>(JtaDataSourceImp.java:269)
        at
com.atomikos.jdbc.SimpleDataSourceBean.checkSetup(SimpleDataSourceBean.java:241)
        at
com.atomikos.jdbc.SimpleDataSourceBean.init(SimpleDataSourceBean.java:284)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1427)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1396)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1359)
Caused by: java.sql.SQLException: Database 'lifecycle' not found.
        at
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
Source)
        at
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown
Source)




When I have Derby running as a Network Server:

    (Spring configuration:)

    <bean id="dataSource"
          class="com.atomikos.jdbc.SimpleDataSourceBean"
          init-method="init"
          destroy-method="close">
        <property name="uniqueResourceName"><value>XADBMS</value></property>
        <!-- set the underlying driver class to use-->
        <property
name="xaDataSourceClassName"><value>org.apache.derby.jdbc.ClientXADataSource40</value></property>-->
        <property name="xaDataSourceProperties">
           
<value>user=root;password=monocongo;serverName=127.0.0.1;portNumber=1527;databaseName=lifecycle;createDatabase=create</value>
        </property>
        <property
name="exclusiveConnectionMode"><value>true</value></property>
        <property name="connectionPoolSize" value="10"/>
    </bean>


ERROR:

org.springframework.jdbc.UncategorizedSQLException: Hibernate operation:
could not execute query; uncategorized SQLException for SQL [select
servicehos0_.SERVICE_HOST_ID as SERVICE1_6_,
servicehos0_.CONNECTION_DETAILS_ID as CONNECTION11_6_,
servicehos0_.DESCRIPTION as DESCRIPT2_6_, servicehos0_.HARDWARE_CONFIG_ID as
HARDWARE12_6_, servicehos0_.HARDWARE_DESCRIPTION as HARDWARE3_6_,
servicehos0_.HOST_STATUS as HOST4_6_, servicehos0_.HOST_TYPE as HOST5_6_,
servicehos0_.LOM_MAC_ADDRESS as LOM6_6_, servicehos0_.LOM_SWITCH_PORT as
LOM7_6_, servicehos0_.MAC_ADDRESS as MAC8_6_, servicehos0_.PHYSICAL_LOCATION
as PHYSICAL9_6_, servicehos0_.SWITCH_PORT as SWITCH10_6_ from SERVICE_HOST
servicehos0_]; SQL state [XJ207]; error code [20000]; executeQuery method
can not be used for update.; nested exception is java.sql.SQLException:
executeQuery method can not be used for update.
        at
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:121)
        at
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:322)
        at
org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
        at
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)
        at
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:378)
        at
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:847)
        at
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:839)
        at
com.sun.network.lifecycle.persistence.dao.GenericDaoHibernateImpl.findAll(GenericDaoHibernateImpl.java:106)
        at
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy22.findAll(Unknown Source)


I was having different issues with Atomikos and JTA before when using MySQL,
insufficient XA support, which is why I'm trying to use Derby.  Is Derby's
XA support also incomplete, or in some way crippled because of this
executeQuery() issue? I saw something in some release notes showing that a
previous issue with executeQuery() being resolved (now returning correct
return values) in the latest Derby release.  Is this not the case, or is
what I'm dealing with above unrelated?

Thanks in advance for any suggestions regarding this issue.

--James
-- 
View this message in context: http://www.nabble.com/Not-creating-database-and-executeQuery%28%29-errors-with-Hibernate%2BSpring%2BAtomikos-tp20801068p20801068.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: Not creating database and executeQuery() errors with Hibernate+Spring+Atomikos

Posted by Kristian Waagan <Kr...@Sun.COM>.
James Adams wrote:
> I am trying to use a Derby database (either embedded or network server) for
> some DAO tests and I am getting the following errors:
>
> Derby running Embedded: 
>
>     (Spring configuration:)
>
>     <bean id="dataSource"
>           class="com.atomikos.jdbc.SimpleDataSourceBean"
>           init-method="init"
>           destroy-method="close">
>         <property name="uniqueResourceName"><value>XADBMS</value></property>
>         <!-- set the underlying driver class to use-->
>         <property
> name="xaDataSourceClassName"><value>org.apache.derby.jdbc.EmbeddedXADataSource40</value></property>
>         <property name="xaDataSourceProperties">
>            
> <value>databaseName=lifecycle;createDatabase=create;shutdownDatabase=shutdown</value>
>         </property>
>         <property
> name="exclusiveConnectionMode"><value>true</value></property>
>         <property name="connectionPoolSize" value="10"/>
>     </bean>
>
>   
Hi James,

Just wondering why both createDatabase and shutdownDatabase are 
specified in the configuration.
Since you're getting the database not found exception, Derby can't be 
creating the database in the first place.

> ERROR:
>
> Error creating bean with name 'dataSource' defined in URL
> [file:/C:/dev/projects/lifecycle/build/classes/applicationContext.xml]:
> Invocation of init method failed; nested exception is java.sql.SQLException:
> Database 'lifecycle' not found.
> org.springframework.beans.factory.BeanCreationException: Error creating bean
> with name 'dataSource' defined in URL
> [file:/C:/dev/projects/lifecycle/build/classes/applicationContext.xml]:
> Invocation of init method failed; nested exception is java.sql.SQLException:
> Database 'lifecycle' not found.
>         at
>
>   
[ snip - stack trace ]
>
>
> When I have Derby running as a Network Server:
>
>     (Spring configuration:)
>
>     <bean id="dataSource"
>           class="com.atomikos.jdbc.SimpleDataSourceBean"
>           init-method="init"
>           destroy-method="close">
>         <property name="uniqueResourceName"><value>XADBMS</value></property>
>         <!-- set the underlying driver class to use-->
>         <property
> name="xaDataSourceClassName"><value>org.apache.derby.jdbc.ClientXADataSource40</value></property>-->
>         <property name="xaDataSourceProperties">
>            
> <value>user=root;password=monocongo;serverName=127.0.0.1;portNumber=1527;databaseName=lifecycle;createDatabase=create</value>
>         </property>
>         <property
> name="exclusiveConnectionMode"><value>true</value></property>
>         <property name="connectionPoolSize" value="10"/>
>     </bean>
>
>
> ERROR:
>
> org.springframework.jdbc.UncategorizedSQLException: Hibernate operation:
> could not execute query; uncategorized SQLException for SQL [select
> servicehos0_.SERVICE_HOST_ID as SERVICE1_6_,
> servicehos0_.CONNECTION_DETAILS_ID as CONNECTION11_6_,
> servicehos0_.DESCRIPTION as DESCRIPT2_6_, servicehos0_.HARDWARE_CONFIG_ID as
> HARDWARE12_6_, servicehos0_.HARDWARE_DESCRIPTION as HARDWARE3_6_,
> servicehos0_.HOST_STATUS as HOST4_6_, servicehos0_.HOST_TYPE as HOST5_6_,
> servicehos0_.LOM_MAC_ADDRESS as LOM6_6_, servicehos0_.LOM_SWITCH_PORT as
> LOM7_6_, servicehos0_.MAC_ADDRESS as MAC8_6_, servicehos0_.PHYSICAL_LOCATION
> as PHYSICAL9_6_, servicehos0_.SWITCH_PORT as SWITCH10_6_ from SERVICE_HOST
> servicehos0_]; SQL state [XJ207]; error code [20000]; executeQuery method
> can not be used for update.; nested exception is java.sql.SQLException:
> executeQuery method can not be used for update.
>         at
>   
[ snip - stack trace ]

This doesn't make sense to me, at least I can't see the query doing any 
update...
Are there any stack traces or error messages in derby.log?

By the way, this exception is only thrown from Statement:
        if (executeType == executeQueryMethod__ && sqlMode == isUpdate__) {
            throw new SqlException(agent_.logWriter_,
                new 
ClientMessageId(SQLState.CANT_USE_EXEC_QUERY_FOR_UPDATE));
        }

So why is isUpdate__ true in this case?
Does this happen also when you disable connection pooling?


Regards,
-- 
Kristian

> I was having different issues with Atomikos and JTA before when using MySQL,
> insufficient XA support, which is why I'm trying to use Derby.  Is Derby's
> XA support also incomplete, or in some way crippled because of this
> executeQuery() issue? I saw something in some release notes showing that a
> previous issue with executeQuery() being resolved (now returning correct
> return values) in the latest Derby release.  Is this not the case, or is
> what I'm dealing with above unrelated?
>
> Thanks in advance for any suggestions regarding this issue.
>
> --James
>   


Re: Not creating database and executeQuery() errors with Hibernate+Spring+Atomikos

Posted by James Adams <mo...@gmail.com>.
Something interesting is that when I start the Derby database from the
Windows XP start menu (Start->Sun Microsystems->Java EE 5 SDK->Start Java
DB) then I get a different result when accessing the DB as a network server
(port 1527):

could not insert: [com.myproject.lifecycle.persistence.entity.ServiceHost]
org.hibernate.exception.GenericJDBCException: could not insert:
[com.myproject.lifecycle.persistence.entity.ServiceHost]
        at
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
        at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
        at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
        at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
        at
org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
        at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
        at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
        at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
        at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
        at
com.sun.network.lifecycle.persistence.dao.GenericDaoHibernateImpl.flush(GenericDaoHibernateImpl.java:177)
        at
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy22.flush(Unknown Source)
        at
com.myproject.lifecycle.persistence.dao.ServiceHostDaoTest.testSaveDeleteFindAll(ServiceHostDaoTest.java:43)
        at
org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
Caused by: com.atomikos.jdbc.AtomikosSQLException
        at
com.atomikos.jdbc.AtomikosSQLException.throwAtomikosSQLException(AtomikosSQLException.java:19)
        at
com.atomikos.jdbc.ConnectionProxy.invoke(ConnectionProxy.java:161)
        at $Proxy19.prepareStatement(Unknown Source)
        at
org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
        at
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94)
        at
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
        at
org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
        at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
Caused by: java.lang.reflect.InvocationTargetException
        at
com.atomikos.jdbc.ConnectionProxy.invoke(ConnectionProxy.java:155)
Caused by: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "/"
at line 1, column 1.
        at
org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown
Source)
        at org.apache.derby.client.am.SqlException.getSQLException(Unknown
Source)
        at org.apache.derby.client.am.Connection.prepareStatement(Unknown
Source)
        at
org.apache.derby.client.am.LogicalConnection.prepareStatement(Unknown
Source)
Caused by: org.apache.derby.client.am.SqlException: Syntax error:
Encountered "/" at line 1, column 1.
        at org.apache.derby.client.am.Statement.completeSqlca(Unknown
Source)
        at
org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown
Source)
        at
org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown
Source)
        at
org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown
Source)
        at
org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown
Source)
        at
org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown
Source)
        at
org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown
Source)
        at
org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown
Source)
        at
org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown
Source)
        at org.apache.derby.client.am.PreparedStatement.prepare(Unknown
Source)
        at org.apache.derby.client.am.Connection.prepareStatementX(Unknown
Source)


-- 
View this message in context: http://www.nabble.com/Not-creating-database-and-executeQuery%28%29-errors-with-Hibernate%2BSpring%2BAtomikos-tp20801068p20801896.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.