the derby version is
Apache Derby Network Server - 10.6.2.1
Derby 10.6 claims support for SEQUENCE
i am using eclipselink;
the sequence in the db was setup with:
DROP TABLE EMPLOYEE;
DROP SEQUENCE Emp_Seq RESTRICT;
CREATE TABLE EMPLOYEE (ID INTEGER NOT NULL, NAME VARCHAR(255), SALARY
INTEGER, PRIMARY KEY (ID));
CREATE SEQUENCE Emp_Seq AS INTEGER START WITH 100 INCREMENT BY 50;
INSERT INTO EMPLOYEE (ID, NAME, SALARY ) VALUES (next value for
Emp_Seq,'Joan', 59000);
INSERT INTO EMPLOYEE (ID, NAME, SALARY ) VALUES (next value for
Emp_Seq,'Gary', 44123);
the Entity uses:
@SequenceGenerator(name = "Emp_Gen", sequenceName = "Emp_Seq",
allocationSize=50)
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"Emp_Gen")
the persistence.xml is:
<?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="EmployeeService">
<jta-data-source>jdbc/sequenceIdGeneration</jta-data-source>
<validation-mode>NONE</validation-mode>
<properties>
<property name="eclipselink.target-server" value="SunAS9"/>
<property name="eclipselink.target-database"
value="org.eclipse.persistence.platform.database.DerbyPlatform"/>
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.jdbc.sequence-connection-pool" value="true"/>
</properties>
</persistence-unit>
</persistence>
the code comes from the book Pro JPA 2 Mastering the Java Persistence API;
so far -- of the 55 netbeans projects i have constructed from 55 of the
examples from
chapters 2,3,4,5 -- i have gotten all but 2 to works properly.
the example using database SEQUENCE fails -- and have not discovered how
to fix after
multiple experiments.
the glassfish log begins with:
FINE: INSERT INTO EMPLOYEE (NAME, SALARY) VALUES (?, ?)
bind => [driscoll, 12345]
FINE: VALUES(1)
WARNING: Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException:
Column 'ID' cannot accept a NULL value.
Error Code: -1
Call: INSERT INTO EMPLOYEE (NAME, SALARY) VALUES (?, ?)
bind => [driscoll, 12345]
Query: InsertObjectQuery(Employee id: 0 name: driscoll salary: 12345)
at
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
the attached zip file is a netbeans 7 project of the example from the book.
Can someone help me to get this example to work with Derby, and
GlassfishV3.0.1 or Glassfish V3.1 if required?
thanks
gary