Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink DataModifyQuery does not throw fatal exception
EclipseLink DataModifyQuery does not throw fatal exception [message #1837294] Wed, 27 January 2021 08:55 Go to next message
Samuel wong is currently offline Samuel wongFriend
Messages: 2
Registered: January 2021
Junior Member
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")
Re: EclipseLink DataModifyQuery does not throw fatal exception [message #1837339 is a reply to message #1837294] Wed, 27 January 2021 20:30 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Table creation is a nice feature, but statements can have issues for any number of valid reasons that aren't failures, and EclipseLink can't, or really even try, to tell the difference.

If you want to have it fail if the tables/fields are not there when it starts up, try adding a session customizer to add validation as described here: https://wiki.eclipse.org/EclipseLink/Examples/JPA/IntegrityChecker
I don't remember if the get in the example code works, as my local code using validation creates a new instance of org.eclipse.persistence.exceptions.IntegrityChecker that I add to the session. This will check each entity and verify the columns in the mappings exist, and give output detailing what might be missing.

Best Regards,
Chris
Re: EclipseLink DataModifyQuery does not throw fatal exception [message #1837489 is a reply to message #1837339] Mon, 01 February 2021 02:32 Go to previous message
Samuel wong is currently offline Samuel wongFriend
Messages: 2
Registered: January 2021
Junior Member
Hi Chris,

Thanks for your response. I've tried implementing the SessionCustomizer and it worked as expected!

Thank you!

Best Regards,
Samuel
Previous Topic:lazy loading vs detached objects
Next Topic:Moxy and enums
Goto Forum:
  


Current Time: Thu Mar 28 21:26:59 GMT 2024

Powered by FUDForum. Page generated in 0.03151 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top