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)

  • Is there a difference between (local), '.' and localhost?
  • SQL JOIN WITH A BUFFER TIME
  • What are the scenarios for using mirroring, log shipping, replication and clustering in SQL Server
  • Could not write value to key \SOFTWARE is displayed for SSMS Install in a Windows 7 machine with an Administrator account
  • How to integrate open ID Login
  • What is the Sql Server equivalent for Oracle's DBMS_ASSERT?
  • 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 Server - Inserted Table
  • What is the difference between Scope_Identity(), Identity(), @@Identity, and Ident_Current()?
  • sql server regex
  • How to monitor database updates from application?
  • Is there a way to convert a varchar to DATETIME in SQL SERVER 2008?
  • Difference between JOIN and INNER JOIN
  • 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.