For test run of the application I am using H2 database 1.4.197. The app is deployed on TomEE 7.1.0 which uses EclipseLink 2.6.4.
I see in logs that during the startup EclipseLink creates tables, sequences etc. Even initialize sequence with value 0:
[EL Fine]: 2019-02-13 20:25:37.442--ServerSession(1981996085)--Connection(1317890500)--Thread(Thread[http-nio-8080-exec-4,5,main])--CREATE TABLE USER (ID BIGINT NOT NULL, FIRSTNAME VARCHAR, LASTNAME VARCHAR, PRIMARY KEY (ID)) [EL Fine]: 2019-02-13 20:25:37.467--ServerSession(1981996085)--Connection(1320052060)--Thread(Thread[http-nio-8080-exec-4,5,main])--CREATE TABLE ADDRESS (ID BIGINT NOT NULL, CITY VARCHAR, HOUSENO VARCHAR, STREET VARCHAR, PRIMARY KEY (ID)) [EL Fine]: 2019-02-13 20:25:37.474--ServerSession(1981996085)--Connection(1328271122)--Thread(Thread[http-nio-8080-exec-4,5,main])--CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT NUMERIC(38), PRIMARY KEY (SEQ_NAME)) [EL Fine]: 2019-02-13 20:25:37.489--ServerSession(1981996085)--Connection(432174967)--Thread(Thread[http-nio-8080-exec-4,5,main])--SELECT * FROM SEQUENCE WHERE SEQ_NAME = 'SEQ_GEN' [EL Fine]: 2019-02-13 20:25:37.51--ServerSession(1981996085)--Connection(1127939384)--Thread(Thread[http-nio-8080-exec-4,5,main])--INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0)
I also was able to connect via H2 console (I started WebServer manually inside the application) and see there tables / sequences.
When I do a simple select via JPQL then all works fine:
Collection<User> getUsers() {
Query query = entityManager.createQuery("select u from User u");
return query.getResultList();
}
However, when I try to insert a new row with persist method:
void saveUser(User user) {
entityManager.persist(user);
}
then I get the exception that tables do not exist:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: org.h2.jdbc.JdbcSQLException: Tabela "SEQUENCE" nie istnieje Table "SEQUENCE" not found; SQL statement: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ? [42102-197] Error Code: 42102 Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ? bind => [50, SEQ_GEN] Query: DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")
EDIT:
User entity implementation:
@Entity
public class User {
private Long id;
private String firstName;
private String lastName;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Column
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
User
entity. It complains Tabela "SEQUENCE" but not about missing tableUser
? And try to change table name SEQUENCE as a reserved word it might cause problems. – pirho