Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 5198 invoked from network); 19 Mar 2008 20:40:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Mar 2008 20:40:19 -0000 Received: (qmail 13444 invoked by uid 500); 19 Mar 2008 20:40:14 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 13421 invoked by uid 500); 19 Mar 2008 20:40:14 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 13412 invoked by uid 99); 19 Mar 2008 20:40:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Mar 2008 13:40:14 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Mar 2008 20:39:42 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 6034D234C0A6 for ; Wed, 19 Mar 2008 13:38:24 -0700 (PDT) Message-ID: <60029911.1205959104389.JavaMail.jira@brutus> Date: Wed, 19 Mar 2008 13:38:24 -0700 (PDT) From: "Fay Wang (JIRA)" To: dev@openjpa.apache.org Subject: [jira] Updated: (OPENJPA-539) Can't create a table with a field of java type "Map" in Derby. In-Reply-To: <1196051670.1205958744955.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/OPENJPA-539?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Fay Wang updated OPENJPA-539: ----------------------------- Attachment: OPENJPA-539.patch The attached patch resolves the reserved word problem in the push-down SQL with Derby when a field of java type Map is defined in an entity. > Can't create a table with a field of java type "Map" in Derby. > -------------------------------------------------------------- > > Key: OPENJPA-539 > URL: https://issues.apache.org/jira/browse/OPENJPA-539 > Project: OpenJPA > Issue Type: Bug > Components: jdbc > Affects Versions: 1.1.0 > Environment: Derby > Reporter: Fay Wang > Fix For: 1.1.0 > > Attachments: OPENJPA-539.patch > > > When a Map field is defined in an entity, the push-down SQL contains Derby reserved word "key", causing the execution to fail. For example: > // Map Type > @ManyToMany > @JoinTable(name="MMCTEA_GMT") > private Map genericizedMapType; > The following SQL will be generated: > CREATE TABLE MMCTEA_GMT (MMCONTAINERTYPEENTITYA_ID INTEGER, key INTEGER, VALUE0_id INTEGER) > Its execution fails with exception stack trace below: > org.apache.openjpa.persistence.PersistenceException: Syntax error: Encountered "key" at line 1, column 61. > at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:553) > at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:453) > at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:159) > at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:119) > at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:187) > at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142) > at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192) > at com.ibm.ws.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:42) > at com.ibm.ws.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:1) > at suite.r70.base.jpaspec.relationships.manyXmany.service.impl.jse.JSEManyXManyEntityService.initializeService(JSEManyXManyEntityService.java:51) > at suite.r70.base.jpaspec.relationships.manyXmany.service.impl.jse.JSEManyXManyEntityService.(JSEManyXManyEntityService.java:40) > at suite.r70.base.jpaspec.relationships.manyXmany.tests.jse.JUnitManyXManyContainerTest.setUpTestCase(JUnitManyXManyContainerTest.java:60) > at suite.r70.base.jpaspec.relationships.manyXmany.tests.jse.JUnitManyXManyContainerTest.setUp(JUnitManyXManyContainerTest.java:45) > at junit.framework.TestCase.runBare(TestCase.java:125) > at junit.framework.TestResult$1.protect(TestResult.java:106) > at junit.framework.TestResult.runProtected(TestResult.java:124) > at junit.framework.TestResult.run(TestResult.java:109) > at junit.framework.TestCase.run(TestCase.java:118) > at junit.framework.TestSuite.runTest(TestSuite.java:208) > at junit.framework.TestSuite.run(TestSuite.java:203) > at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35) > at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) > at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) > at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) > at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) > at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) > at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) > Caused by: java.sql.SQLException: Syntax error: Encountered "key" at line 1, column 61. > at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) > at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) > at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source) > at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source) > at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source) > at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source) > at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source) > at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unknown Source) > at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225) > at org.apache.openjpa.lib.jdbc.DelegatingStatement.executeUpdate(DelegatingStatement.java:114) > at org.apache.openjpa.jdbc.schema.SchemaTool.executeSQL(SchemaTool.java:1185) > at org.apache.openjpa.jdbc.schema.SchemaTool.createTable(SchemaTool.java:949) > at org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:526) > at org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:344) > at org.apache.openjpa.jdbc.schema.SchemaTool.run(SchemaTool.java:321) > at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:501) > ... 26 more > This is because in HandlerRelationMapTableFieldStrategy.map method, the following method > is called with "key" hardcoded to be the column name: > _kcols = HandlerStrategies.map(key, "key", _kio, adapt); > The proposed change is to concatenate field name (in this case, "genericizedMapType") > with "_key" to make the resulting column name a non-reserved word in any > database: > _kcols = HandlerStrategies.map(key, field.getName + "_key", _kio, adapt); -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.