hirikarate
hirikarate

Reputation: 3315

JPA causes trouble for itself

I'm using JPA/EclipseLink, it throws this exception

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'NAME' in 'field list'

Below is the generated query:

Call: SELECT id, DTYPE, fullname, NAME, code FROM PERSON WHERE ((accountId = ?) AND (DTYPE = ?)) bind => [1, Employee]

in which

@Entity
@Table(name = "PERSON")
public class Person 
        implements Serializable {
    ....

    @Column(name = "fullname", nullable = false)
    public String getFullName() {
        return this.fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    ....
}

@Entity
@Table(name="EMPLOYEE")
@PrimaryKeyJoinColumn(name="personId")
public class Employee 
        extends Person
        implements Serializable {

    ....    

    @Column(name="code")
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}

I don't have the NAME column on neither PERSON table nor EMPLOYEE table, why does it casually add that column to the query and cause the problem for itself (and for me)?

--- EDITED ----- I don't have any name property or member or something similar to that word in either PERSON nor EMPLOYEE entity.

Upvotes: 3

Views: 1555

Answers (1)

Chris
Chris

Reputation: 21165

NAME looks like it is defaulting (since you seem to set the field names as lower case), so check for a getName/setName methods in the Person class. Are you using an orm.xml file?

If you still cannot find the problem, turn EclipseLink logging to Finest: and check the log during predeployment/deployment stages. The EclipseLink processing for the Person and Employee classes should show why it is determining there should be a NAME field.

Upvotes: 2

Related Questions