Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] TableGenerator question: is the provider responsible for initializing rows?

My @TableGenerator-related question goes like this:

Suppose I create a table like this:

CREATE TABLE jpa_sequence ( sequence_name VARCHAR(100) NOT NULL PRIMARY KEY, last_value BIGINT NOT NULL DEFAULT 0 );

(Typed off the cuff so ignore any SQL syntax errors--you get the idea.)

Suppose further I do not (myself) insert any rows into this table.

Suppose, next, I have a @TableGenerator annotation somewhere in my persistence unit like this:

@TableGenerator(
  table="jpa_sequence",
  pkColumnName="sequence_name",
  name="fred",
  pkColumnValue="fred",
  valueColumnName="last_value",
  initialValue=7000,
  allocationSize=500
)

Note in particular the initialValue() assignment.

If I do absolutely nothing else (other than persist an instance of this entity), is the JPA provider mandated to insert new rows into this table (which, in this case, should only happen once, ever)?  Or must I seed the row initially?

My JPA unit tests seem to show that the "big 3" providers all insert rows into this table automatically as necessary.  But, then again, my JPA tests end with an EntityTransaction.rollback(), so perhaps the row insertions are not actually taking place.

(I'm making some giant pervasive across-the-whole-source-tree changes in our application, due to the inability to override the @GeneratedValue annotation in a subclass--so I need to make sure I'm doing everything I need to to get this to work.)

Thanks,
Laird

--
http://about.me/lairdnelson


Back to the top