Hi,
I used your annotation and my test case runs fine.
Given your pkColumnName = "table_name", openjpa internally makes this
column name valid for a given database. This code is in ValueTableJDBCSeq:
protected Column addPrimaryKeyColumn(Table table) {
DBDictionary dict = getConfiguration().getDBDictionaryInstance();
Column pkColumn = table.addColumn(dict.getValidColumnName
(getPrimaryKeyColumn(), table));
...
}
Note that the return value from dict.getValidColumnName is table_name0.
From my jdbc log, the table jdo_keygen is created as:
CREATE TABLE jdo_keygen (TABLE_NAME0 VARCHAR(254) NOT NULL, LAST_USED_ID
BIGINT, PRIMARY KEY (TABLE_NAME0))
As a result, there is no problem executing
SELECT LAST_USED_ID FROM jdo_keygen WHERE TABLE_NAME0 = ? FOR UPDATE
I am using openjpa trunk for this exercise. You might want to turn on jdbc log
to see how create jdo_keygen is created.
Hope this helps.
Fay
----- Original Message ----
From: Michael Simons <[email protected]>
To: [email protected]
Sent: Monday, June 22, 2009 6:48:17 AM
Subject: Problem with @TableGenerator [OpenJPA 1.2.2]
Hello,
Here's my annotation:
@TableGenerator(name = "pkGenSessionConfig", table = "jdo_keygen",
pkColumnName =
"table_name", valueColumnName = "last_used_id", pkColumnValue =
"session_config", allocationSize
= 10)
@Id
@GeneratedValue(strategy=GenerationType.TABLE,
generator="pkGenSessionConfig")
@Column(name="session_config_id", unique=true, nullable=false)
private int id;
And here's the according SQL generated by OpenJPA:
Unknown column 'TABLE_NAME0' in 'where clause' {prepstmnt 32845046 SELECT
LAST_USED_ID FROM
jdo_keygen WHERE TABLE_NAME0 = ? FOR UPDATE [params=(String) session_config]}
[code=1054,
state=42S22]
Question: Where does OpenJPA take "TABLE_NAME0" from while
pkColumnValue="table_name"
Kind Regards,
Michael