问题描述
我有一个实体类,其主键上带有以下注释:@GeneratedValue(strategy = GenerationType.AUTO)
.但是,当我尝试persist
此类的实例时,我得到了
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
它要查找的表在数据库中绝对不存在.它正在连接数据库的用户可以创建表.是应该自动创建OPENJPA_SEQUENCE_TABLE,还是必须为此创建它?如果是这样,它期望的表架构是什么?我正在使用openjpa-1.2.2.jar.
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.
编辑:我查看了 main()
的JavaDoc ,因为它可以选择在命令行上添加序列表,但是在openjpa-1.2.2.jar中不存在. org.apache.openjpa.jdbc.schema
可以,但是TableJDBCSequence
不在其中.
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.
推荐答案
默认情况下,除非在persistence.xml中启用了SynchronizeMappings属性,否则OpenJPA不会自动创建任何表(包括序列表).但是,这实际上仅对调试有用,因为我认为每次应用程序启动时它都会重置数据库:
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)"/>
您还可以从命令行使用OpenJPA MappingTool生成模式脚本:
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
有关映射工具和运行时正向映射的更多信息,请参见: http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/ref_guide_mapping.html#ref_guide_ddl_examples
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
您最后的选择是手动创建表.这是Oracle的脚本;您可能可以相当轻松地将其转换为SQL Server:
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))
这篇关于OpenJPA 1-未创建序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!