JPA,SQlite没有这样的表格:SEQUENCE [英] JPA, SQlite no such table: SEQUENCE
问题描述
我在使用JPA和SQlite时遇到问题.
I have a problem with JPA and SQlite.
我已经从表创建了一个实体.我生成的实体看起来像:
I have created an Entity from Table. My generated Entity looks like:
@Entity
@Table(name="sqliteTestTable")
public class Test implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int id;
@Column(name="name")
private String name;
public Test() {
}
------
}
当我尝试保留一些测试对象时,出现以下错误: (我已经在mysql上执行了相同的代码而没有问题)
When i try to persist a few Test objects i get following error: (I have executed the same code on mysql without problems)
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: no such table: SEQUENCE
Error Code: 0
Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [50, SEQ_GEN_TABLE]
Query: DataModifyQuery(name="SEQ_GEN_TABLE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
我该如何解决这个问题?
How can i solve this problem?
推荐答案
如果数据库平台不支持IDENTITY,则IDENTITY将默认为TABLE.
IDENTITY will default to TABLE if IDENTITY is not supported in the database platform.
对于TABLE,您需要创建一个序列表.如果您有ElipseLink创建表,它将自动为您创建表,否则,您需要自己创建它.
For TABLE you need to have a sequence table created. If you have ElipseLink create your tables it will automatically be created for you, otherwise you need to create it yourself.
如果SQlite具有IDENTITY支持,则可以创建自己的DatabasePlatform子类来添加身份支持.
If SQlite has IDENTITY support, then you can create your own DatabasePlatform subclass that adds the identity support.
通常,我永远不建议使用IDENTITY,它不支持预分配,并且会导致性能下降.
In general I would never recommend using IDENTITY, it does not support pre-allocation and will lead to poor performance.
这篇关于JPA,SQlite没有这样的表格:SEQUENCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!