openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <kwsut...@gmail.com>
Subject Re: Change of MappingDefaults breaks OPENJPA_SEQUENCE_TABLE
Date Mon, 11 Jun 2012 14:44:18 GMT
Hi Alexey,
Are you saying that without your ImprovedMappingDefaults class, everything
is working okay?  On the surface, I'm not seeing the connection between the
column mapping processing and the "missing" sequence table.  Dumb question,
are you sure your persistence.xml that has the SynchronizeMappings property
is in use?  As your Googling found, the use of the SynchronizeMappings
property should ensure that all of the necessary tables are created and/or
modified before use.

You could turn on Trace and check to see if the tables are maybe being
created under a different schema, or some other processing that is
unexpected or not consistent.

Kevin

On Sat, Jun 9, 2012 at 2:11 AM, Alexey Romanov
<alexey.v.romanov@gmail.com>wrote:

> I've tried to change mapping defaults to use lowercase underscore column
> names:
>
> package ru.focusmedia.odp.server.datastore.jpa.impl;
>
> import org.apache.openjpa.jdbc.identifier.DBIdentifier;
> import org.apache.openjpa.jdbc.schema.Column;
> import org.apache.openjpa.jdbc.schema.Table;
> import org.apache.openjpa.persistence.jdbc.PersistenceMappingDefaults;
>
> public class ImprovedMappingDefaults extends PersistenceMappingDefaults {
>    @Override
>    protected void correctName(Table table, Column col) {
>        DBIdentifier name =
> DBIdentifier.newColumn(col.getIdentifier().getName(), true);
>        DBIdentifier validName = dict.getValidColumnName(name, table);
>        DBIdentifier correctedName = DBIdentifier
>                .newColumn(addUnderscores(validName.getName()));
>        col.setIdentifier(correctedName);
>        table.addCorrectedColumnName(correctedName, true);
>    }
>
>    // taken from Hibernate's ImprovedNamingStrategy
>    private static String addUnderscores(String name) {
>        StringBuffer buf = new StringBuffer(name.replace('.', '_'));
>        for (int i = 1; i < buf.length() - 1; i++) {
>            if (Character.isLowerCase(buf.charAt(i - 1))
>                    && Character.isUpperCase(buf.charAt(i))
>                    && Character.isLowerCase(buf.charAt(i + 1))) {
>                buf.insert(i++, '_');
>            }
>        }
>        return buf.toString().toLowerCase();
>    }
> }
>
> and added
>
> <property name="openjpa.jdbc.MappingDefaults"
>
>  value="ru.focusmedia.odp.server.datastore.jpa.impl.ImprovedMappingDefaults"/>
>
> to persistence.xml. However, this produces the following error:
>
> org.apache.openjpa.persistence.PersistenceException: Table/View
> 'OPENJPA_SEQUENCE_TABLE' does not exist. {SELECT SEQUENCE_VALUE FROM
> OPENJPA_SEQUENCE_TABLE WHERE ID = ? FOR UPDATE WITH RR} [code=20000,
> state=42X05]
>    at
> org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4918)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4878)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:110)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:62)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:66)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at org.apache.openjpa.util.ImplHelper.generateValue(ImplHelper.java:160)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.util.ImplHelper.generateFieldValue(ImplHelper.java:144)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignField(JDBCStoreManager.java:756)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:493)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:469)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:740)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:135)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:612)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2977)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1054)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2112)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2072)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1843)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at org.apache.openjpa.kernel.QueryImpl.isInMemory(QueryImpl.java:973)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:853)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:330)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> com.mysema.query.jpa.impl.AbstractJPAQuery.getSingleResult(AbstractJPAQuery.java:249)
> ~[querydsl-jpa-2.6.0.jar:na]
>    at
> com.mysema.query.jpa.impl.AbstractJPAQuery.uniqueResult(AbstractJPAQuery.java:327)
> ~[querydsl-jpa-2.6.0.jar:na]
>    at
> com.mysema.query.jpa.impl.AbstractJPAQuery.uniqueResult(AbstractJPAQuery.java:312)
> ~[querydsl-jpa-2.6.0.jar:na]
>    at
> ru.focusmedia.odp.server.datastore.jpa.repository.RepositoryImpl.getRoleByName(RepositoryImpl.java:523)
> [classes/:na]
>    at
> ru.focusmedia.odp.server.datastore.jpa.repository.RepositoryImpl.access$4(RepositoryImpl.java:521)
> [classes/:na]
>    at
> ru.focusmedia.odp.server.datastore.jpa.repository.RepositoryImpl$14.call(RepositoryImpl.java:572)
> [classes/:na]
>    at
> ru.focusmedia.odp.server.datastore.jpa.repository.RepositoryImpl$14.call(RepositoryImpl.java:1)
> [classes/:na]
>    at
> ru.focusmedia.odp.server.datastore.jpa.repository.RepositoryImpl.transact(RepositoryImpl.java:705)
> [classes/:na]
>    at
> ru.focusmedia.odp.server.datastore.jpa.repository.RepositoryImpl.createUser(RepositoryImpl.java:568)
> [classes/:na]
>    at
> ru.focusmedia.odp.server.datastore.jpa.repository.RepositoryTest.userCanBeCreated(RepositoryTest.java:158)
> [test-classes/:na]
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> ~[na:1.6.0_31]
>    at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> ~[na:1.6.0_31]
>    at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> ~[na:1.6.0_31]
>    at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_31]
>    at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
> [junit-4.10.jar:na]
>    at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> [junit-4.10.jar:na]
>    at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
> [junit-4.10.jar:na]
>    at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> [junit-4.10.jar:na]
>    at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> [junit-4.10.jar:na]
>    at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
> [junit-4.10.jar:na]
>    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
> [junit-4.10.jar:na]
>    at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
> [junit-4.10.jar:na]
>    at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
> [junit-4.10.jar:na]
>    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
> [junit-4.10.jar:na]
>    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
> [junit-4.10.jar:na]
>    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
> [junit-4.10.jar:na]
>    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
> [junit-4.10.jar:na]
>    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
> [junit-4.10.jar:na]
>    at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> [junit-4.10.jar:na]
>    at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
> [junit-4.10.jar:na]
>    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
> [junit-4.10.jar:na]
>    at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> [.cp/:na]
>    at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> [.cp/:na]
>    at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> [.cp/:na]
>    at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> [.cp/:na]
>    at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> [.cp/:na]
>    at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> [.cp/:na]
> Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException:
> Table/View 'OPENJPA_SEQUENCE_TABLE' does not exist. {SELECT
> SEQUENCE_VALUE FROM OPENJPA_SEQUENCE_TABLE WHERE ID = ? FOR UPDATE
> WITH RR} [code=20000, state=42X05]
>    at
> org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:247)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:227)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$000(LoggingConnectionDecorator.java:72)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.prepareStatement(LoggingConnectionDecorator.java:279)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:133)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.lib.jdbc.ConfiguringConnectionDecorator$ConfiguringConnection.prepareStatement(ConfiguringConnectionDecorator.java:140)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:122)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:449)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:429)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:418)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.prepareStatement(TableJDBCSeq.java:807)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.getSequence(TableJDBCSeq.java:546)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.setSequence(TableJDBCSeq.java:588)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq$AllocateSequenceRunnable.run(TableJDBCSeq.java:893)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:455)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:300)
> ~[openjpa-2.2.0.jar:2.2.0]
>    at
> org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)
> ~[openjpa-2.2.0.jar:2.2.0]
>    ... 58 common frames omitted
>
> before any tables are created. Googling says this may happen because
> SynchronizeMappings isn't set, but it is in my case:
>
> <property name="openjpa.jdbc.SynchronizeMappings"
>    value="buildSchema(ForeignKeys=true)" />
> <property name="openjpa.jdbc.DBDictionary"
>    value="derby(NextSequenceQuery=VALUES NEXT VALUE FOR {0})" />
>
> How can I get this to work?
>
> Yours, Alexey Romanov
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message