You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Laird Nelson <lj...@gmail.com> on 2011/08/26 19:49:43 UTC

GenerationType.TABLE question: column name suffixed with 0?

I'm seeing some odd trace output in OpenJPA 2.1.0 when attempting to grab a
value from a sequence table I've set up (via the @TableGeneratorannotation).

I have created a table named ngp.jpa_sequence with two columns: name and
last_value.  name is a varchar(100); last_value is a bigint.  name is the
primary key.  Both columns are non-nullable.  This is in the H2 database,
v1.3.158, if it matters.

My @TableGenerator looks like this:

@javax.persistence.TableGenerator(
    name = "fred",
    table = "jpa_sequence",
    pkColumnName = "name",
    valueColumnName = "last_value",
    pkColumnValue = "fred",
    allocationSize = 500
  )

My @GeneratedValue looks like this:

@javax.persistence.GeneratedValue(strategy =
javax.persistence.GenerationType.TABLE, generator = "fred")

OpenJPA tries to read a column called "NAME0", which is not defined
anywhere.

OpenJPA begins setting up, and then it does this (huge stack; stand back):

<openjpa-2.1.0-r422266:1071316 fatal general error>
org.apache.openjpa.persistence.PersistenceException: Column "NAME0" not
found; SQL statement:
SELECT LAST_VALUE FROM ngp.jpa_sequence WHERE NAME0 = ? FOR UPDATE
[42122-151] {SELECT LAST_VALUE FROM ngp.jpa_sequence WHERE NAME0 = ? FOR
UPDATE} [code=42122, state=42S22]
    at
org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4869)
    at
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4829)
    at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
    at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:110)
    at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:62)
    at
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:66)
    at org.apache.openjpa.util.ImplHelper.generateValue(ImplHelper.java:160)
    at
org.apache.openjpa.util.ImplHelper.generateFieldValue(ImplHelper.java:144)
    at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignField(JDBCStoreManager.java:785)
    at
org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:493)
    at
org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:469)
    at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:769)
    at
org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:135)
    at
org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:605)
    at
org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2966)
    at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40)
    at
org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1047)
    at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2091)
    at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2051)
    at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1822)
    at
org.apache.openjpa.kernel.DelegatingBroker.flush(DelegatingBroker.java:1037)
    at
org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:654)
    at com.foo.TestCaseFoobar.testInsert(TestCaseFoobar.java:40)
    [snip]
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Column "NAME0"
not found; SQL statement:
SELECT LAST_VALUE FROM ngp.jpa_sequence WHERE NAME0 = ? FOR UPDATE
[42122-151] {SELECT LAST_VALUE FROM ngp.jpa_sequence WHERE NAME0 = ? FOR
UPDATE} [code=42122, state=42S22]
    at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:281)
    at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:261)
    at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$000(LoggingConnectionDecorator.java:72)
    at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.prepareStatement(LoggingConnectionDecorator.java:313)
    at
org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:155)
    at
org.apache.openjpa.lib.jdbc.ConfiguringConnectionDecorator$ConfiguringConnection.prepareStatement(ConfiguringConnectionDecorator.java:158)
    at
org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:144)
    at
org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:561)
    at
org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:541)
    at
org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:530)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.prepareStatement(TableJDBCSeq.java:807)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.getSequence(TableJDBCSeq.java:546)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.setSequence(TableJDBCSeq.java:588)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq$AllocateSequenceRunnable.run(TableJDBCSeq.java:893)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:455)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:300)
    at
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)
    ... 54 more
NestedThrowables:
org.h2.jdbc.JdbcSQLException: Column "NAME0" not found; SQL statement:
SELECT LAST_VALUE FROM ngp.jpa_sequence WHERE NAME0 = ? FOR UPDATE
[42122-151]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
    at org.h2.message.DbException.get(DbException.java:167)
    at org.h2.message.DbException.get(DbException.java:144)
    at
org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:134)
    at org.h2.expression.Comparison.optimize(Comparison.java:154)
    at org.h2.command.dml.Select.prepare(Select.java:783)
    at org.h2.command.Parser.prepare(Parser.java:202)
    at org.h2.command.Parser.prepareCommand(Parser.java:214)
    at org.h2.engine.Session.prepareLocal(Session.java:426)
    at org.h2.engine.Session.prepareCommand(Session.java:374)
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1089)
    at
org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:71)
    at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:597)
    at
org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:157)
    at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.prepareStatement(LoggingConnectionDecorator.java:310)
    at
org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:155)
    at
org.apache.openjpa.lib.jdbc.ConfiguringConnectionDecorator$ConfiguringConnection.prepareStatement(ConfiguringConnectionDecorator.java:158)
    at
org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:144)
    at
org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:561)
    at
org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:541)
    at
org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:530)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.prepareStatement(TableJDBCSeq.java:807)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.getSequence(TableJDBCSeq.java:546)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.setSequence(TableJDBCSeq.java:588)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq$AllocateSequenceRunnable.run(TableJDBCSeq.java:893)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:455)
    at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:300)
    at
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)
    at org.apache.openjpa.util.ImplHelper.generateValue(ImplHelper.java:160)
    at
org.apache.openjpa.util.ImplHelper.generateFieldValue(ImplHelper.java:144)
    at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignField(JDBCStoreManager.java:785)
    at
org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:493)
    at
org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:469)
    at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:769)
    at
org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:135)
    at
org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:605)
    at
org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2966)
    at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40)
    at
org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1047)
    at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2091)
    at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2051)
    at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1822)
    at
org.apache.openjpa.kernel.DelegatingBroker.flush(DelegatingBroker.java:1037)
    at
org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:654)
    at com.foo.TestCaseFoobar.testInsert(TestCaseFoobar.java:40)
    [snip]

I've grepped our source base to see if this is pilot error, but didn't find
anything.  Where is that "0" coming from?

Best,
Laird

-- 
http://about.me/lairdnelson

Re: GenerationType.TABLE question: column name suffixed with 0?

Posted by Michael Dick <mi...@gmail.com>.
The issue is OPENJPA-2045<https://issues.apache.org/jira/browse/OPENJPA-2045>,
if the workaround doesn't work for you let us know and we'll take a look at
that aspect too.

-mike

On Thu, Sep 1, 2011 at 8:53 AM, ljnelson <lj...@gmail.com> wrote:

> On Thu, Sep 1, 2011 at 9:52 AM, Michael Dick [via OpenJPA] <
> ml-node+6750086-1384401919-155969@n2.nabble.com> wrote:
>
> > You're right, this is a bug. "NAME" is in the default set of reserved
> words
> >
> > that can't be used as column names. It appears to be valid for H2 though
> > and
> > we should handle it appropriately. Can you file a JIRA issue, or would
> you
> > like me to do that on your behalf?
> >
>
> Sounds like you know roughly where it is; if you wouldn't mind filing it
> yourself it would probably be a better bug report for it.  :-)
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/GenerationType-TABLE-question-column-name-suffixed-with-0-tp6729676p6750091.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: GenerationType.TABLE question: column name suffixed with 0?

Posted by ljnelson <lj...@gmail.com>.
On Thu, Sep 1, 2011 at 9:52 AM, Michael Dick [via OpenJPA] <
ml-node+6750086-1384401919-155969@n2.nabble.com> wrote:

> You're right, this is a bug. "NAME" is in the default set of reserved words
>
> that can't be used as column names. It appears to be valid for H2 though
> and
> we should handle it appropriately. Can you file a JIRA issue, or would you
> like me to do that on your behalf?
>

Sounds like you know roughly where it is; if you wouldn't mind filing it
yourself it would probably be a better bug report for it.  :-)

Best,
Laird

-- 
http://about.me/lairdnelson


--
View this message in context: http://openjpa.208410.n2.nabble.com/GenerationType-TABLE-question-column-name-suffixed-with-0-tp6729676p6750091.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: GenerationType.TABLE question: column name suffixed with 0?

Posted by Michael Dick <mi...@gmail.com>.
You're right, this is a bug. "NAME" is in the default set of reserved words
that can't be used as column names. It appears to be valid for H2 though and
we should handle it appropriately. Can you file a JIRA issue, or would you
like me to do that on your behalf?

You can escape the name column as a workaround  :
@javax.persistence.TableGenerator(
    name = "fred",
    table = "jpa_sequence",
    pkColumnName = "\"name\"",
    valueColumnName = "last_value",
    pkColumnValue = "fred",
    allocationSize = 500)

-mike

On Fri, Aug 26, 2011 at 1:36 PM, Laird Nelson <lj...@gmail.com> wrote:

> On Fri, Aug 26, 2011 at 1:49 PM, Laird Nelson <lj...@gmail.com> wrote:
>
> > OpenJPA tries to read a column called "NAME0", which is not defined
> > anywhere.
> >
>
> Changing the name of the sequence table column from "NAME" to
> "SEQUENCE_NAME" fixed the problem.  Bug in OpenJPA, I think.  Maybe in the
> H2 dictionary?
>
> Best,
> Laird
> --
> http://about.me/lairdnelson
>

Re: GenerationType.TABLE question: column name suffixed with 0?

Posted by Laird Nelson <lj...@gmail.com>.
On Fri, Aug 26, 2011 at 1:49 PM, Laird Nelson <lj...@gmail.com> wrote:

> OpenJPA tries to read a column called "NAME0", which is not defined
> anywhere.
>

Changing the name of the sequence table column from "NAME" to
"SEQUENCE_NAME" fixed the problem.  Bug in OpenJPA, I think.  Maybe in the
H2 dictionary?

Best,
Laird
-- 
http://about.me/lairdnelson