Reputation: 211
My Entity class
@Entity
class MasterStccycode{
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 3)
@Column(name = "CODE")
private String code;
@Size(max = 100)
@Column(name = "DESC")
private String desc;
}
my JPA Query
SELECT t.code, t.desc FROM MasterStccycode t
then I have this following exception
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'DESC'.
Error Code: 156
Call: SELECT CODE, DESC FROM master_stccycode Query: ReportQuery(referenceClass=MasterStccycode sql="SELECT CODE, DESC FROM master_stccycode")
I know the solution is to wrap the DESC
keyword with []
into [DESC]
but how can I do this on JPA QL?
Upvotes: 0
Views: 1162
Reputation: 18379
DESC is a reserved word on most databases. You should rename the field.
You could also quote the field, but just renaming it would be best.
@Column(name = "\"DESC\"")
Upvotes: 2