我使用 Eclipselink 作为 JPA 提供程序和嵌入式 Apache Derby 数据库。当我运行项目时,我得到如下异常:
内部异常:java.sql.SQLSyntaxErrorException:语法错误:在第 1 行第 31 列遇到“NOT”。
错误代码:-1
调用:创建表项(ID VARCHAR NOT NULL、CODE VARCHAR、EXCLUSIVETAX NUMBER(10,5)、NAME VARCHAR、UNITPRICE NUMBER(10,5)、PRIMARY KEY (ID))
查询:DataModifyQuery(sql="CREATE TABLE ITEM (ID VARCHAR NOT NULL, CODE VARCHAR, EXCLUSIVETAX NUMBER(10,5), NAME VARCHAR, UNITPRICE NUMBER(10,5), PRIMARY KEY (ID))")
[EL 警告]:2013-03-06 18:04:41.827--ServerSession(1650627452)--异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions .DatabaseException
内部异常:java.sql.SQLSyntaxErrorException:语法错误:在第 1 行第 71 列遇到“(”。
错误代码:-1
调用:CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT NUMBER(19), PRIMARY KEY (SEQ_NAME))
查询:DataModifyQuery(sql="CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT NUMBER(19), PRIMARY KEY (SEQ_NAME))")
[EL 信息]:2013-03-06 18:04:41.856--ServerSession(1650627452)--尝试在事务之外执行读取查询时检测到通信失败。正在尝试重试查询。错误是:异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
persistence.xml 是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="StockKeeperPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.mycompany.entities.stock.Item</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:sampledb;create=true"/>
<property name="javax.persistence.jdbc.password" value="app"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.user" value="app"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
这里有什么问题?是NOT
不是允许在那个声明中?如果不允许,为什么查询被这样框定?