OpenJPA 1 – sequence table not being created

I have an entity class with the following annotation on its primary key: @GeneratedValue(strategy = GenerationType.AUTO). However, when I try to persist an instance of this class, I get

com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name ‘OPENJPA_SEQUENCE_TABLE’.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)

  • Beside compatibility with SQL Server 2000 and 2005, is there any other issue to use datetime2
  • case statement in SQL, how to return multiple variables?
  • Error - Exclusive access could not be obtained because the database is in use
  • How to add multiple columns to a table and add default constraint on one of them?
  • SQL Get Latest Unique Rows
  • What are the differences between CHECKSUM() and BINARY_CHECKSUM() and when/what are the appropriate usage scenarios?
  • The table it’s looking for definitely does not exist in the database. The user it’s connecting to the database as can create tables. Should it be creating OPENJPA_SEQUENCE_TABLE automatically, or do I have to do that for it? If so, what’s the table schema it’s expecting? I’m using openjpa-1.2.2.jar.

    Edit: I looked at main()‘s JavaDoc since it has an option to add the sequence table on the command line, but org.apache.openjpa.jdbc.schema.TableJDBCSequence does not exist in openjpa-1.2.2.jar. org.apache.openjpa.jdbc.schema does, but TableJDBCSequence is not in it.

  • SQL - “incrementing” a char value causes collation error
  • How to get week numbers for whole year in SQL Server
  • Alter user defined type in Sql Server
  • How to restore and existing backup from an existing database to a new one without affecting the original?
  • SQL Server check case-sensitivity?
  • How to check if columns are being used by views?
  • 2 Solutions collect form web for “OpenJPA 1 – sequence table not being created”

    By default, OpenJPA doesn’t create any of the tables (including the sequence table) automatically unless you have the SynchronizeMappings property enabled in your persistence.xml. However, this is really only good for debugging purposes since I think it resets the database each time the application starts up:

    <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
    

    You can also use the OpenJPA MappingTool from the command line to generate the schema script:

    java org.apache.openjpa.jdbc.meta.MappingTool -action buildSchema -foreignKeys true
    

    More information about the Mapping Tool and runtime forward mapping is available here: http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/ref_guide_mapping.html#ref_guide_ddl_examples

    Your final option is to just create the table manually. Here is the script for Oracle; you can probably convert it to SQL Server fairly easily:

    CREATE TABLE openjpa_sequence_table (ID tinyint(4) NOT NULL, SEQUENCE_VALUE bigint(20) default NULL, PRIMARY KEY (ID)) 
    

    In my case changing the GenerationType.AUTO into GenerationType.IDENTITY solved the problem. Ofcourse this is only a solution if you can change the entity.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.