我開發了一些單元測試,但是在所有的SQL語句上都失敗了,您能否看看這個日誌和配置?嵌入的Glassfish SQL語句失敗
Jul 01, 2012 4:33:05 PM org.glassfish.persistence.common.Java2DBProcessorHelper executeDDLs WARNING: PER01000: Got SQLException executing statement "CREATE TABLE CAR (ID BIGINT NOT NULL, BRAND VARCHAR(255) NOT NULL, DESCRIPTION VARCHAR(255), FUEL VARCHAR(255) NOT NU\ LL, GEARBOX VARCHAR(255) NOT NULL, KILOMETRES INTEGER NOT NULL, MODEL VARCHAR(255) NOT NULL, PRICE INTEGER NOT NULL, TYPE VARCHAR(255) NOT NULL, YEAR INTEGER NOT NULL, EQUIPM\ ENT_ID BIGINT, SECURITY_ID BIGINT, PRIMARY KEY (ID))": java.sql.SQLSyntaxErrorException: Syntax error: Encountered "YEAR" at line 1, column 263. Jul 01, 2012 4:33:05 PM org.glassfish.persistence.common.Java2DBProcessorHelper executeDDLs WARNING: PER01000: Got SQLException executing statement "CREATE TABLE VEHICLE (ID BIGINT NOT NULL, MAKE VARCHAR(255) NOT NULL, MODEL VARCHAR(255) NOT NULL, TRIM VARCHAR(255) \ NOT NULL, YEAR INTEGER NOT NULL, PRIMARY KEY (ID))": java.sql.SQLSyntaxErrorException: Syntax error: Encountered "TRIM" at line 1, column 100. Jul 01, 2012 4:33:06 PM org.glassfish.persistence.common.Java2DBProcessorHelper executeDDLs WARNING: PER01000: Got SQLException executing statement "ALTER TABLE CAR ADD CONSTRAINT FK_CAR_SECURITY_ID FOREIGN KEY (SECURITY_ID) REFERENCES SECURITY (ID)": java.sql.SQLSy\ ntaxErrorException: 'ALTER TABLE' cannot be performed on 'CAR' because it does not exist. Jul 01, 2012 4:33:06 PM org.glassfish.persistence.common.Java2DBProcessorHelper executeDDLs WARNING: PER01000: Got SQLException executing statement "ALTER TABLE CAR ADD CONSTRAINT CAR_EQUIPMENT_ID FOREIGN KEY (EQUIPMENT_ID) REFERENCES EQUIPMENT (ID)": java.sql.SQLSy\ ntaxErrorException: 'ALTER TABLE' cannot be performed on 'CAR' because it does not exist. Jul 01, 2012 4:33:06 PM com.sun.ejb.containers.BaseContainer initializeHome INFO: EJB5181:Portable JNDI names for EJB VehicleEJB: [java:global/classes/VehicleEJB!com.thevehiclelist.VehicleEJB, java:global/classes/VehicleEJB] Jul 01, 2012 4:33:06 PM com.sun.ejb.containers.BaseContainer initializeHome INFO: EJB5181:Portable JNDI names for EJB BookEJB: [java:global/classes/BookEJB!se.while_se.BookEJB, java:global/classes/BookEJB] Jul 01, 2012 4:33:06 PM com.sun.ejb.containers.BaseContainer initializeHome INFO: EJB5181:Portable JNDI names for EJB CarEJB: [java:global/classes/CarEJB, java:global/classes/CarEJB!se.while_se.CarEJB] Jul 01, 2012 4:33:07 PM org.eclipse.persistence.session.file:/tmp/gfembed468260415984552053tmp/applications/classes/_carcmsPU WARNING: Local Exception Stack: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "TRIM" at line 1, column 39. Error Code: 20000 Call: INSERT INTO VEHICLE (ID, MAKE, MODEL, TRIM, YEAR) VALUES (?, ?, ?, ?, ?) bind => [5 parameters bound] Query: InsertObjectQuery(Vehicle [id=1, year=2007, make=Volvo, model=V70, trim=2.4D]) at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333) at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:644) at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535) at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1717) at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:253) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:342) at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:162) at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:177) at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:472) at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80) at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90) at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:287) at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58) at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:844) at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:743) at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108) at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85) at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2871)
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
version="2.0">
<persistence-unit name="carcmsPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/__default</jta-data-source>
<class>se.while_se.Book</class>
<class>se.while_se.Car</class>
<class>com.thevehiclelist.Vehicle</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:MyTestDb;create=true" />
<property name="javax.persistence.jdbc.user" value="" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
</properties>
</persistence-unit>
</persistence>
而且我的pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.8.2.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
我沒有任何線索,什麼都可以,周圍有很多都tryed谷歌上搜索,但沒有沒有找到任何這個東西的參考代碼..你可以請看看我的配置有什麼問題或建議我的一些文件?
最佳regars
年份看起來像奧斯卡保留字。在創建表格聲明中,嘗試將年份改爲caryear甚至幾年,然後重試。 – Namphibian