openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dianne Richards <diann...@gmail.com>
Subject Re: Change of MappingDefaults breaks OPENJPA_SEQUENCE_TABLE
Date Wed, 20 Jun 2012 17:04:18 GMT
Oops - I just looked more closely at the output, and it's not what you
want. I'll keep going.

Dianne

On Wed, Jun 20, 2012 at 11:53 AM, Dianne Richards <dianner4@gmail.com>wrote:

> Hi Alexey - I was able to reproduce this problem with a simple test case
> and debug it. I think you can get what you want by changing the following
> line in your ImprovedMappingDefaults:
>
> DBIdentifier.newColumn(col.getIdentifier().getName(), true);
>
> Change the "true" to "false". What's happening is the true says to delimit
> the name, which has a rippling effect. I don't think you want this.
>
> It works on my simple test, so hopefully it will work for you.
>
> Dianne
>
>
> 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
>>
>
>
>
> --
> Thanks - Dianne
>



-- 
Thanks - Dianne

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