0

i am trying to query two database tables using a result class with the following query:

public List<UserStatus> getUserStatus(String username) {
   String qlString = 
           "SELECT NEW no.uia.slit.ejb.UserStatus(file.filename, file.uploadTime, mod.title, mod.dueAt) "
           + "FROM DownloadableFile file, Module mod"
           + "where file.moduleId = mod.id";
   TypedQuery<UserStatus> query = em.createQuery(qlString, UserStatus.class);
   return query.getResultList();

}

Running this i get the following error:

Caused by: <openjpa-2.3.0-nonfinal-1540826-r422266:1542644 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Encountered "mod ." at character 71, but expected: ["(", "+", "-", ":", "?", "ABS", "AVG", "CASE", "COALESCE", "CONCAT", "COUNT", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "ENTRY", "INDEX", "KEY", "LENGTH", "LOCATE", "LOWER", "MAX", "MIN", "MOD", "NULLIF", "SIZE", "SQRT", "SUBSTRING", "SUM", "TRIM", "TYPE", "UPPER", "VALUE", <BOOLEAN_LITERAL>, <DATE_LITERAL>, <DECIMAL_LITERAL>, <IDENTIFIER>, <INTEGER_LITERAL>, <STRING_LITERAL2>, <STRING_LITERAL>, <TIMESTAMP_LITERAL>, <TIME_LITERAL>].

My result class is as follows:

public class UserStatus {

private String title;
private Date dueAt;
private String filename;
private Timestamp uploadTime;
public UserStatus(){
    super();
}
public UserStatus(String filename, Timestamp uploadTime, String title, Date dueAt) {
    this.filename = filename;
    this.uploadTime = uploadTime;
    this.title = title;
    this.dueAt = dueAt;
}

public void setTitle(String title) {
    this.title = title;
}

public String getTitle() {
    return title;
}

public void setDueAt(Date dueAt) {
    this.dueAt = dueAt;
}
public Date getDueAt() {
    return dueAt;
}

public void setFileName(String filename) {
    this.filename = filename;
}

public String getFileName() {
    return filename;
}

public void setUploadTime(Timestamp uploadTime) {
    this.uploadTime = uploadTime;
}

public Timestamp getUploadTime() {
    return uploadTime;
}

}

i used an example i found to make the query and i cant figure out what is wrong, i know it says "mod . " is wrong but why.

edit: https://blogs.oracle.com/adf/entry/ejb_dc_using_jpql_constructor this is the example i used.

2 Answers 2

1

"MOD" is a reserved keyword used by the JPQL language, so you can't use it for your variable names. Pick some other name not in that list

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for quick answer, that worked. Stupid mistake should read documentation better from now on..
1

mod (ducumentation) is a reserved word in sql change it to module and it should work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.