I am using SQLServer and I have an entity "Enrollment" that contains student (Student) as the ManyToOne relationship.
I've tried to set the student column name as "USER" which is a SQL reserved keywords.
I've also set eclipselink.ddl-generation=drop-and-create-tables
which will drop and create the table.
NOTE: I do know the reserved SQL keyword can be escaped with [USER] or "USER"
@ManyToOne
@JoinColumn(name = "USER")
private Student student;
When I execute the test main code, I do get a DatabaseException from EclipseLink and the table did not get created. However, the code successfully executed without throwing any fatal Exception that stops the execution.
It did throw Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'USER'.
but I expect it to fail instead.
Is this a bug on EclipseLink itself or are there any configuration to make it fail?
Refer to the full logs below:
[EL Warning]: 2021-01-27 14:54:12.789--ServerSession(231311211)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'USER'.
Error Code: 156
Call: CREATE TABLE ENROLLMENT (ENROLLMENT_KEY NUMERIC(19) NOT NULL, COURSE_KEY NUMERIC(19) NULL, USER NUMERIC(19) NULL, PRIMARY KEY (ENROLLMENT_KEY))
Query: DataModifyQuery(sql="CREATE TABLE ENROLLMENT (ENROLLMENT_KEY NUMERIC(19) NOT NULL, COURSE_KEY NUMERIC(19) NULL, USER NUMERIC(19) NULL, PRIMARY KEY (ENROLLMENT_KEY))")
[EL Warning]: 2021-01-27 14:54:12.797--ServerSession(231311211)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot find the object "ENROLLMENT" because it does not exist or you do not have permissions.
Error Code: 4902
Call: ALTER TABLE ENROLLMENT ADD CONSTRAINT ENROLLMENT_COURSE_KEY FOREIGN KEY (COURSE_KEY) REFERENCES COURSE (COURSE_KEY)
Query: DataModifyQuery(sql="ALTER TABLE ENROLLMENT ADD CONSTRAINT ENROLLMENT_COURSE_KEY FOREIGN KEY (COURSE_KEY) REFERENCES COURSE (COURSE_KEY)")
[EL Warning]: 2021-01-27 14:54:12.802--ServerSession(231311211)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'STUDENT_SEQ'.
Error Code: 208
Call: SELECT NEXT VALUE FOR STUDENT_SEQ
Query: ValueReadQuery(sql="SELECT NEXT VALUE FOR STUDENT_SEQ")
[EL Warning]: 2021-01-27 14:54:12.806--ServerSession(231311211)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'COURSE_SEQ'.
Error Code: 208
Call: SELECT NEXT VALUE FOR COURSE_SEQ
Query: ValueReadQuery(sql="SELECT NEXT VALUE FOR COURSE_SEQ")
[EL Warning]: 2021-01-27 14:54:12.81--ServerSession(231311211)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'ENROLLMENT_SEQ'.
Error Code: 208
Call: SELECT NEXT VALUE FOR ENROLLMENT_SEQ
Query: ValueReadQuery(sql="SELECT NEXT VALUE FOR ENROLLMENT_SEQ")
question from:
https://stackoverflow.com/questions/65914877/eclipselink-datamodifyquery-does-not-throw-fatal-exception 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…