I cant select in DB2 - java

I have an application consisting of: Spring, WebSphere, accessing DB2 jdbc.
Everything is set up ok, the application is usually published, because when I go to select a seat at any table I get this following error.
OsjsSQLErrorCodeSQLExceptionTranslator DEBUG - Translating SQLException with SQL
state '42Y07 ', error code '30000', message [Schema 'DBPROD' does not exist]; SQL was
[SELECT * FROM DBPROD.EXPUR_CONS_CRIVO] for task [PreparedStatementCallback]
[10/24/11 10:11:54:257 EST] 0000001b SystemOut The 10:11:54.249 [WebContainer: 1]
ERROR bcbwahdHistoricoDescontoDAOImpl - [requestID A8IUK52K =]
HistoricoDescontoDAOImpl.consultarHistoricoDesconto Terminating with error ()
org.springframework.dao.DataAccessResourceFailureException: PreparedStatementCallback;
SQL [SELECT * FROM DBPROD.EXPUR_CONS_CRIVO]; Schema 'DBPROD' does not exist;
java.sql.SQLSyntaxErrorException nested exception is: Schema 'DBPROD' does not exist
at [spring-jdbc-3.0.1.RELEASE.jar: 3.0.1.RELEASE]
at [spring-jdbc-3.0.1.RELEASE.jar: 3.0.1.RELEASE]
Caused by: org.apache.derby.impl.jdbc.EmbedSQLException: Schema 'DBPROD' does not exist
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source) [derby-10.5.3.0_1.jar:na]
... 191 common frames omitted
Caused by: org.apache.derby.iapi.error.StandardException: Schema 'DBPROD' does not exist
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getSchemaDescriptor(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.compile.QueryTreeNode.getSchemaDescriptor(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.compile.QueryTreeNode.getSchemaDescriptor(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.compile.FromBaseTable.bindTableDescriptor(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.compile.FromBaseTable.bindNonVTITables(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source) [derby-10.5.3.0_1.jar:na]
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source) [derby-10.5.3.0_1.jar:na]
... 185 common frames omitted
my user has full access to the database, since I do not know what to do.

SQL State codes beginning with '42' refer usually to Syntax errors, but in your Case its pretty clear that Schema is missing.
Check these Links hope they will help you solve this problem:
CURRENT SCHEMA special register
how do i get the current schema on DB2 if i have a JDBC conneciton?

As it has been mentioned, the error messages you get are from an Apache Derby JDBC driver. Check that you chose the correct datasource when you configured your application in WebSphere.

Related

Hibernate error when executing JDBC statements - unexpected token 'UNIQUE'

I searched around and the only similar StackOverflow thread doesn't address what I'm looking for.
I have defined an auxillary database object in Hibernate like so:
<database-object>
<create>ALTER TABLE project ADD CONSTRAINT UNIQUE `unique_id` (`userId`);</create>
<drop></drop>
</database-object>
Upon setting up my database and running against passing tests, I get this error thrown:
01:56:04.337> WARN ExceptionHandlerLoggedImpl:27 GenerationTarget encountered exception accepting command : Error executing DDL "ALTER TABLE project ADD CONSTRAINT UNIQUE `unique_id` (`userId`);" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "ALTER TABLE project ADD CONSTRAINT UNIQUE `unique_id` (`userId`);" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:458)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:442)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:406)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:169)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:138)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:124)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:164)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:81)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:335)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:728)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:746)
at com.ekotrope.server.jdo.BaseJdoTestClass.startServices(BaseJdoTestClass.java:221)
at com.ekotrope.server.jdo.BaseJdoTestClass.beforeClass(BaseJdoTestClass.java:112)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
Caused by: java.sql.SQLSyntaxErrorException: unexpected token: UNIQUE
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyStatement.execute(NewProxyStatement.java:75)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 31 more
Caused by: org.hsqldb.HsqlException: unexpected token: UNIQUE
at org.hsqldb.error.Error.parseError(Unknown Source)
at org.hsqldb.ParserBase.unexpectedToken(Unknown Source)
at org.hsqldb.ParserBase.checkIsNonCoreReservedIdentifier(Unknown Source)
at org.hsqldb.ParserDQL.checkIsSchemaObjectName(Unknown Source)
at org.hsqldb.ParserDQL.readNewSchemaObjectName(Unknown Source)
at org.hsqldb.ParserDQL.readNewDependentSchemaObjectName(Unknown Source)
at org.hsqldb.ParserDDL.compileAlterTable(Unknown Source)
at org.hsqldb.ParserDDL.compileAlter(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 35 more
This is incredibly confusing because executing the above statement within my database (MariaDB) is perfectly valid, yet JDBC doesn't recognize a perfectly fine statement.

IBM DB2 Connection error with autoReconnect

I am using db2jcc4.jar version 4.19.26 and JDBC4 .
When I am adding autoReconnect=true in the connection URL ,
<datasource jta="true" jndi-name="java:/jdbc/Name" pool-name="Name" enabled="true" use-ccm="false">
<connection-url>jdbc:db2://host:port/db?autoReconnect=true</connection-url>
<driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
<driver>db2jcc4.jar</driver> ....
I am getting the following error :
Caused by: javax.resource.ResourceException: Could not create connection
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:347)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:354)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:288)
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.createConnectionEventListener(SemaphoreArrayListManagedConnectionPool.java:1166)
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:446)
at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getTransactionNewConnection(AbstractPool.java:541)
at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:442)
at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:379)
... 129 more
Caused by: com.ibm.db2.jcc.am.DisconnectNonTransientException: [jcc][t4][2034][11148][4.19.26] Execution failed due to a distribution protocol error that caused deallocation of the conversation.
A DRDA Data Stream Syntax Error was detected. Reason: 0x2110. ERRORCODE=-4499, SQLSTATE=58009
at com.ibm.db2.jcc.am.kd.a(Unknown Source)
at com.ibm.db2.jcc.am.kd.a(Unknown Source)
at com.ibm.db2.jcc.t4.y.j(Unknown Source)
at com.ibm.db2.jcc.t4.z.bb(Unknown Source)
at com.ibm.db2.jcc.t4.z.y(Unknown Source)
at com.ibm.db2.jcc.t4.z.T(Unknown Source)
at com.ibm.db2.jcc.t4.z.i(Unknown Source)
at com.ibm.db2.jcc.t4.z.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.c(Unknown Source)
at com.ibm.db2.jcc.t4.b.b(Unknown Source)
at com.ibm.db2.jcc.t4.b.b(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.<init>(Unknown Source)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
at com.ibm.db2.jcc.DB2Driver.connect(Unknown Source)
at com.ibm.db2.jcc.DB2Driver.connect(Unknown Source)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:322)
... 136 more
IBM documentation shows that the resolution to this issue is to use a different version of the JCC jar, hope that this works out for you. You could've at least added what version of DB you are using in the question. Please check this solution if it works for your situation!
The solution suggested in this documentation is to:
Use JCC driver version 4.11.77 and above or upgrade to DB2 V9.5 FP7 or DB2 V9.7 FP3a and above.

Connecting to a derby database with JDBC in spring

I'm trying to connect to a derby database.
I have the following error in the console after running the app:
01:07:31.698 [main] INFO o.s.j.d.DriverManagerDataSource - Loaded JDBC driver: org.apache.derby.jdbc.EmbeddedDriver
Creating records
01:07:31.826 [main] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL update
01:07:31.828 [main] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL statement [INSERT INTO `students` (name,age) VALUES (?,?)]
01:07:31.845 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
01:07:31.845 [main] DEBUG o.s.j.d.DriverManagerDataSource - Creating new JDBC DriverManager Connection to [jdbc:derby:c:\temp\database\test01;create=true]
Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Failed to start database 'c:\temp\database\test01' with class loader sun.misc.Launcher$AppClassLoader#6d9bf996, see the next exception for details.
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:628)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:907)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:968)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:978)
at Student.dao.StudentImplementationOfDao.insert(StudentImplementationOfDao.java:22)
at main.Application.main(Application.java:31)
Caused by: java.sql.SQLException: Failed to start database 'c:\temp\database\test01' with class loader sun.misc.Launcher$AppClassLoader#6d9bf996, see the next exception for details.
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.seeNextException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.bootDatabase(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.AutoloadedDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:155)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:120)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
... 6 more
Caused by: java.sql.SQLException: Failed to start database 'c:\temp\database\test01' with class loader sun.misc.Launcher$AppClassLoader#6d9bf996, see the next exception for details.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 24 more
Caused by: java.sql.SQLException: Another instance of Derby may have already booted the database C:\temp\database\test01.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
... 21 more
Caused by: ERROR XSDB6: Another instance of Derby may have already booted the database C:\temp\database\test01.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.privGetJBMSLockOnDB(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.getJBMSLockOnDB(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
at org.apache.derby.impl.store.raw.RawStore.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
at org.apache.derby.impl.store.access.RAMAccessManager.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
at org.apache.derby.impl.db.BasicDatabase.bootStore(Unknown Source)
at org.apache.derby.impl.db.BasicDatabase.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startProviderService(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.findProviderAndStartService(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startPersistentService(Unknown Source)
at org.apache.derby.iapi.services.monitor.Monitor.startPersistentService(Unknown Source)
... 21 more
The code that I built to connect to the database is:
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
ds.setUrl("jdbc:derby:c:\\temp\\database\\test01;create=true");
ds.setUsername("");
ds.setPassword("");
siod.setDataSource(ds);
From what I could understand in the errors shown above is something to do with a PreparedStatement that tries to gets inserted.
The sql statement is:
"INSERT INTO `students` (name,age) VALUES (?,?)
I parsed this sql to a instantiated JdbcTemplate which has the dataSource mentioned above.
Here is the exact code:
public void insert(Student student)
{
//ds is simply the dataSource that gets created in the code example above
JdbcTemplate create = new JdbcTemplate(ds);
create.update(sql,new Object[]{student.name,student.age});
}
I'm sure this question has a simple answer but I just don't understand what exactly is causing this error. Is it the statement? Is it cause the connection fails? How do I solve whatever makes my code fail?
Thank you
Another instance of Derby may have already booted the database
C:\temp\database\test01.
With an embedded database, only the application that it is embedded in can access it. Check to make sure that your previous application is fully stopped. The simplest solution for that is to just restart your operating system, but if you are familiar with killing processes, you can look for all your java processes and kill them.
Another thing I have seen sometimes is somebody copying the files from a Derby database to another location, while that Derby database was being used. This leaves the copy of the database in a locked state. That's likely not your problem though.

BoneCP & Derby - How to properly shutdown

I have:
BoneCP CONNECTION_POOL = ...;
CONNECTION_POOL.getConfig().setJdbcUrl("jdbc:derby:database...;shutdown=true");
Connection connection = CONNECTION_POOL.getConnection();
connection.close();
CONNECTION_POOL.shutdown();
However this results in the following exception:
3274 [com.google.common.base.internal.Finalizer] ERROR com.jolbox.bonecp.ConnectionPartition - Error while closing off internal db connection
java.sql.SQLException: Cannot close a connection while a transaction is still active.
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.checkForTransactionInProgress(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.close(Unknown Source)
at com.jolbox.bonecp.ConnectionPartition$1.finalizeReferent(ConnectionPartition.java:187)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.base.internal.Finalizer.cleanUp(Finalizer.java:154)
at com.google.common.base.internal.Finalizer.run(Finalizer.java:127)
How can I avoid this exception. I've tried every possible way I can think of...
Unless you are running v0.8.1-beta2 or greater, set "disableConnectionTracking" to true in your config.
Please note that you should also expect an SQLException from Derby after a SUCCESSFUL shutdown: http://db.apache.org/derby/docs/dev/devguide/tdevdvlp40464.html

Hibernate/JPA + Derby - SELECT statement has too many items in GROUP BY, ORDER BY or select list

I use Hibernate for JPA DB mapping with Derby DB. For a complex object structure I am getting "org.apache.derby.client.am.SqlException: SELECT statement has too many items in GROUP BY, ORDER BY or select list":
org.apache.derby.client.am.SqlException: SELECT statement has too many items in GROUP BY, ORDER BY or select list.
org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
org.hibernate.loader.Loader.doQuery(Loader.java:673)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:229)
org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:120)
org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:228)
sun.reflect.GeneratedMethodAccessor376.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
$Proxy74.merge(Unknown Source)
sun.reflect.GeneratedMethodAccessor376.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
$Proxy41.merge(Unknown Source)
Has anyone run into this problem and if what was the solution? I am thinking of
switching to MySQL
lazily load some attributes (fetch=FetchType.LAZY)
redesign DB schema (that might be difficult now, DB is generated using Hyperjaxb from XSD schemas and shemas would have to be changed)
For which solution would you go? Do you know what are the limitations of Derby for SQL statements?
Try debugging it with show_sql=true doc
Check the SQL generated and try debugging it .
I believe Derby allows approximately 32,000 columns in the GROUP BY clause. There are similar limits for ORDER BY, and for the columns named in the SELECT list.

Categories

Resources